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 | |
| 958 | template <class _CharT> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 959 | struct _LIBCPP_TYPE_VIS_ONLY regex_traits |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 960 | { |
| 961 | public: |
| 962 | typedef _CharT char_type; |
| 963 | typedef basic_string<char_type> string_type; |
| 964 | typedef locale locale_type; |
Dan Albert | e7a75cc | 2014-07-22 18:37:52 -0700 | [diff] [blame] | 965 | #ifdef __ANDROID__ |
| 966 | typedef uint16_t char_class_type; |
| 967 | #else |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 968 | typedef ctype_base::mask char_class_type; |
Dan Albert | e7a75cc | 2014-07-22 18:37:52 -0700 | [diff] [blame] | 969 | #endif |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 970 | |
Dan Albert | e7a75cc | 2014-07-22 18:37:52 -0700 | [diff] [blame] | 971 | #ifdef __ANDROID__ |
| 972 | static const char_class_type __regex_word = 0x8000; |
| 973 | #else |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 974 | static const char_class_type __regex_word = 0x80; |
Dan Albert | e7a75cc | 2014-07-22 18:37:52 -0700 | [diff] [blame] | 975 | #endif |
| 976 | |
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 | bcaf4d5 | 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 | { |
| 1959 | if (__s.__at_first_ && __s.__current_ == __s.__first_) |
| 1960 | { |
| 1961 | __s.__do_ = __state::__accept_but_not_consume; |
| 1962 | __s.__node_ = this->first(); |
| 1963 | } |
| 1964 | else |
| 1965 | { |
| 1966 | __s.__do_ = __state::__reject; |
| 1967 | __s.__node_ = nullptr; |
| 1968 | } |
| 1969 | } |
| 1970 | |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 1971 | // __r_anchor |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1972 | |
| 1973 | template <class _CharT> |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 1974 | class __r_anchor |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1975 | : public __owns_one_state<_CharT> |
| 1976 | { |
| 1977 | typedef __owns_one_state<_CharT> base; |
| 1978 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1979 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1980 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1981 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1982 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1983 | __r_anchor(__node<_CharT>* __s) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 1984 | : base(__s) {} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1985 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1986 | virtual void __exec(__state&) const; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1987 | }; |
| 1988 | |
| 1989 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1990 | void |
| 1991 | __r_anchor<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1992 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1993 | if (__s.__current_ == __s.__last_) |
| 1994 | { |
| 1995 | __s.__do_ = __state::__accept_but_not_consume; |
| 1996 | __s.__node_ = this->first(); |
| 1997 | } |
| 1998 | else |
| 1999 | { |
| 2000 | __s.__do_ = __state::__reject; |
| 2001 | __s.__node_ = nullptr; |
| 2002 | } |
| 2003 | } |
| 2004 | |
| 2005 | // __match_any |
| 2006 | |
| 2007 | template <class _CharT> |
| 2008 | class __match_any |
| 2009 | : public __owns_one_state<_CharT> |
| 2010 | { |
| 2011 | typedef __owns_one_state<_CharT> base; |
| 2012 | |
| 2013 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2014 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2015 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2016 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2017 | __match_any(__node<_CharT>* __s) |
| 2018 | : base(__s) {} |
| 2019 | |
| 2020 | virtual void __exec(__state&) const; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2021 | }; |
| 2022 | |
| 2023 | template <class _CharT> |
| 2024 | void |
| 2025 | __match_any<_CharT>::__exec(__state& __s) const |
| 2026 | { |
| 2027 | if (__s.__current_ != __s.__last_ && *__s.__current_ != 0) |
| 2028 | { |
| 2029 | __s.__do_ = __state::__accept_and_consume; |
| 2030 | ++__s.__current_; |
| 2031 | __s.__node_ = this->first(); |
| 2032 | } |
| 2033 | else |
| 2034 | { |
| 2035 | __s.__do_ = __state::__reject; |
| 2036 | __s.__node_ = nullptr; |
| 2037 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2038 | } |
| 2039 | |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2040 | // __match_any_but_newline |
| 2041 | |
| 2042 | template <class _CharT> |
| 2043 | class __match_any_but_newline |
| 2044 | : public __owns_one_state<_CharT> |
| 2045 | { |
| 2046 | typedef __owns_one_state<_CharT> base; |
| 2047 | |
| 2048 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2049 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2050 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2051 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2052 | __match_any_but_newline(__node<_CharT>* __s) |
| 2053 | : base(__s) {} |
| 2054 | |
| 2055 | virtual void __exec(__state&) const; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2056 | }; |
| 2057 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2058 | template <> _LIBCPP_FUNC_VIS void __match_any_but_newline<char>::__exec(__state&) const; |
| 2059 | template <> _LIBCPP_FUNC_VIS void __match_any_but_newline<wchar_t>::__exec(__state&) const; |
| 2060 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2061 | // __match_char |
| 2062 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2063 | template <class _CharT> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2064 | class __match_char |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2065 | : public __owns_one_state<_CharT> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2066 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2067 | typedef __owns_one_state<_CharT> base; |
| 2068 | |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2069 | _CharT __c_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2070 | |
| 2071 | __match_char(const __match_char&); |
| 2072 | __match_char& operator=(const __match_char&); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2073 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2074 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2075 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2076 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2077 | __match_char(_CharT __c, __node<_CharT>* __s) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2078 | : base(__s), __c_(__c) {} |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2079 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2080 | virtual void __exec(__state&) const; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2081 | }; |
| 2082 | |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2083 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2084 | void |
| 2085 | __match_char<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2086 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2087 | if (__s.__current_ != __s.__last_ && *__s.__current_ == __c_) |
| 2088 | { |
| 2089 | __s.__do_ = __state::__accept_and_consume; |
| 2090 | ++__s.__current_; |
| 2091 | __s.__node_ = this->first(); |
| 2092 | } |
| 2093 | else |
| 2094 | { |
| 2095 | __s.__do_ = __state::__reject; |
| 2096 | __s.__node_ = nullptr; |
| 2097 | } |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2098 | } |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2099 | |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2100 | // __match_char_icase |
| 2101 | |
| 2102 | template <class _CharT, class _Traits> |
| 2103 | class __match_char_icase |
| 2104 | : public __owns_one_state<_CharT> |
| 2105 | { |
| 2106 | typedef __owns_one_state<_CharT> base; |
| 2107 | |
| 2108 | _Traits __traits_; |
| 2109 | _CharT __c_; |
| 2110 | |
| 2111 | __match_char_icase(const __match_char_icase&); |
| 2112 | __match_char_icase& operator=(const __match_char_icase&); |
| 2113 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2114 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2115 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2116 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2117 | __match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s) |
| 2118 | : base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {} |
| 2119 | |
| 2120 | virtual void __exec(__state&) const; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2121 | }; |
| 2122 | |
| 2123 | template <class _CharT, class _Traits> |
| 2124 | void |
| 2125 | __match_char_icase<_CharT, _Traits>::__exec(__state& __s) const |
| 2126 | { |
| 2127 | if (__s.__current_ != __s.__last_ && |
| 2128 | __traits_.translate_nocase(*__s.__current_) == __c_) |
| 2129 | { |
| 2130 | __s.__do_ = __state::__accept_and_consume; |
| 2131 | ++__s.__current_; |
| 2132 | __s.__node_ = this->first(); |
| 2133 | } |
| 2134 | else |
| 2135 | { |
| 2136 | __s.__do_ = __state::__reject; |
| 2137 | __s.__node_ = nullptr; |
| 2138 | } |
| 2139 | } |
| 2140 | |
| 2141 | // __match_char_collate |
| 2142 | |
| 2143 | template <class _CharT, class _Traits> |
| 2144 | class __match_char_collate |
| 2145 | : public __owns_one_state<_CharT> |
| 2146 | { |
| 2147 | typedef __owns_one_state<_CharT> base; |
| 2148 | |
| 2149 | _Traits __traits_; |
| 2150 | _CharT __c_; |
| 2151 | |
| 2152 | __match_char_collate(const __match_char_collate&); |
| 2153 | __match_char_collate& operator=(const __match_char_collate&); |
| 2154 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2155 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2156 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2157 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2158 | __match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s) |
| 2159 | : base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {} |
| 2160 | |
| 2161 | virtual void __exec(__state&) const; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2162 | }; |
| 2163 | |
| 2164 | template <class _CharT, class _Traits> |
| 2165 | void |
| 2166 | __match_char_collate<_CharT, _Traits>::__exec(__state& __s) const |
| 2167 | { |
| 2168 | if (__s.__current_ != __s.__last_ && |
| 2169 | __traits_.translate(*__s.__current_) == __c_) |
| 2170 | { |
| 2171 | __s.__do_ = __state::__accept_and_consume; |
| 2172 | ++__s.__current_; |
| 2173 | __s.__node_ = this->first(); |
| 2174 | } |
| 2175 | else |
| 2176 | { |
| 2177 | __s.__do_ = __state::__reject; |
| 2178 | __s.__node_ = nullptr; |
| 2179 | } |
| 2180 | } |
| 2181 | |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2182 | // __bracket_expression |
| 2183 | |
| 2184 | template <class _CharT, class _Traits> |
| 2185 | class __bracket_expression |
| 2186 | : public __owns_one_state<_CharT> |
| 2187 | { |
| 2188 | typedef __owns_one_state<_CharT> base; |
| 2189 | typedef typename _Traits::string_type string_type; |
| 2190 | |
| 2191 | _Traits __traits_; |
| 2192 | vector<_CharT> __chars_; |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2193 | vector<_CharT> __neg_chars_; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2194 | vector<pair<string_type, string_type> > __ranges_; |
| 2195 | vector<pair<_CharT, _CharT> > __digraphs_; |
| 2196 | vector<string_type> __equivalences_; |
Dan Albert | bcaf4d5 | 2014-07-29 19:23:39 +0000 | [diff] [blame] | 2197 | typename regex_traits<_CharT>::char_class_type __mask_; |
| 2198 | typename regex_traits<_CharT>::char_class_type __neg_mask_; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2199 | bool __negate_; |
| 2200 | bool __icase_; |
| 2201 | bool __collate_; |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2202 | bool __might_have_digraph_; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2203 | |
| 2204 | __bracket_expression(const __bracket_expression&); |
| 2205 | __bracket_expression& operator=(const __bracket_expression&); |
| 2206 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2207 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2208 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2209 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2210 | __bracket_expression(const _Traits& __traits, __node<_CharT>* __s, |
| 2211 | bool __negate, bool __icase, bool __collate) |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2212 | : base(__s), __traits_(__traits), __mask_(), __neg_mask_(), |
| 2213 | __negate_(__negate), __icase_(__icase), __collate_(__collate), |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2214 | __might_have_digraph_(__traits_.getloc().name() != "C") {} |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2215 | |
| 2216 | virtual void __exec(__state&) const; |
| 2217 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2218 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2219 | bool __negated() const {return __negate_;} |
| 2220 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2221 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2222 | void __add_char(_CharT __c) |
| 2223 | { |
| 2224 | if (__icase_) |
| 2225 | __chars_.push_back(__traits_.translate_nocase(__c)); |
| 2226 | else if (__collate_) |
| 2227 | __chars_.push_back(__traits_.translate(__c)); |
| 2228 | else |
| 2229 | __chars_.push_back(__c); |
| 2230 | } |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2231 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2232 | void __add_neg_char(_CharT __c) |
| 2233 | { |
| 2234 | if (__icase_) |
| 2235 | __neg_chars_.push_back(__traits_.translate_nocase(__c)); |
| 2236 | else if (__collate_) |
| 2237 | __neg_chars_.push_back(__traits_.translate(__c)); |
| 2238 | else |
| 2239 | __neg_chars_.push_back(__c); |
| 2240 | } |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2241 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2242 | void __add_range(string_type __b, string_type __e) |
| 2243 | { |
| 2244 | if (__collate_) |
| 2245 | { |
| 2246 | if (__icase_) |
| 2247 | { |
| 2248 | for (size_t __i = 0; __i < __b.size(); ++__i) |
| 2249 | __b[__i] = __traits_.translate_nocase(__b[__i]); |
| 2250 | for (size_t __i = 0; __i < __e.size(); ++__i) |
| 2251 | __e[__i] = __traits_.translate_nocase(__e[__i]); |
| 2252 | } |
| 2253 | else |
| 2254 | { |
| 2255 | for (size_t __i = 0; __i < __b.size(); ++__i) |
| 2256 | __b[__i] = __traits_.translate(__b[__i]); |
| 2257 | for (size_t __i = 0; __i < __e.size(); ++__i) |
| 2258 | __e[__i] = __traits_.translate(__e[__i]); |
| 2259 | } |
| 2260 | __ranges_.push_back(make_pair( |
| 2261 | __traits_.transform(__b.begin(), __b.end()), |
| 2262 | __traits_.transform(__e.begin(), __e.end()))); |
| 2263 | } |
| 2264 | else |
| 2265 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2266 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2267 | if (__b.size() != 1 || __e.size() != 1) |
| 2268 | throw regex_error(regex_constants::error_collate); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2269 | #endif // _LIBCPP_NO_EXCEPTIONS |
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 | bcaf4d5 | 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 | bcaf4d5 | 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 | { |
Dan Albert | 4dc5b21 | 2015-01-15 14:32:55 -0800 | [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) |
| 2962 | : base(__s), __exp_(__exp), __invert_(__invert), __mexp_(__mexp) {} |
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; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3022 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3023 | default: |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 3024 | throw regex_error(regex_constants::__re_err_grammar); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3025 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3026 | } |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3027 | return __first; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3028 | } |
| 3029 | |
| 3030 | template <class _CharT, class _Traits> |
| 3031 | template <class _ForwardIterator> |
| 3032 | _ForwardIterator |
| 3033 | basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first, |
| 3034 | _ForwardIterator __last) |
| 3035 | { |
| 3036 | if (__first != __last) |
| 3037 | { |
| 3038 | if (*__first == '^') |
| 3039 | { |
| 3040 | __push_l_anchor(); |
| 3041 | ++__first; |
| 3042 | } |
| 3043 | if (__first != __last) |
| 3044 | { |
| 3045 | __first = __parse_RE_expression(__first, __last); |
| 3046 | if (__first != __last) |
| 3047 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3048 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3049 | if (__temp == __last && *__first == '$') |
| 3050 | { |
| 3051 | __push_r_anchor(); |
| 3052 | ++__first; |
| 3053 | } |
| 3054 | } |
| 3055 | } |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3056 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3057 | if (__first != __last) |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 3058 | throw regex_error(regex_constants::__re_err_empty); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3059 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3060 | } |
| 3061 | return __first; |
| 3062 | } |
| 3063 | |
| 3064 | template <class _CharT, class _Traits> |
| 3065 | template <class _ForwardIterator> |
| 3066 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3067 | basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first, |
| 3068 | _ForwardIterator __last) |
| 3069 | { |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3070 | __owns_one_state<_CharT>* __sa = __end_; |
| 3071 | _ForwardIterator __temp = __parse_ERE_branch(__first, __last); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3072 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3073 | if (__temp == __first) |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 3074 | throw regex_error(regex_constants::__re_err_empty); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3075 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3076 | __first = __temp; |
| 3077 | while (__first != __last && *__first == '|') |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3078 | { |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3079 | __owns_one_state<_CharT>* __sb = __end_; |
| 3080 | __temp = __parse_ERE_branch(++__first, __last); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3081 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3082 | if (__temp == __first) |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 3083 | throw regex_error(regex_constants::__re_err_empty); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3084 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3085 | __push_alternation(__sa, __sb); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3086 | __first = __temp; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3087 | } |
| 3088 | return __first; |
| 3089 | } |
| 3090 | |
| 3091 | template <class _CharT, class _Traits> |
| 3092 | template <class _ForwardIterator> |
| 3093 | _ForwardIterator |
| 3094 | basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first, |
| 3095 | _ForwardIterator __last) |
| 3096 | { |
| 3097 | _ForwardIterator __temp = __parse_ERE_expression(__first, __last); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3098 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3099 | if (__temp == __first) |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 3100 | throw regex_error(regex_constants::__re_err_empty); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3101 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3102 | do |
| 3103 | { |
| 3104 | __first = __temp; |
| 3105 | __temp = __parse_ERE_expression(__first, __last); |
| 3106 | } while (__temp != __first); |
| 3107 | return __first; |
| 3108 | } |
| 3109 | |
| 3110 | template <class _CharT, class _Traits> |
| 3111 | template <class _ForwardIterator> |
| 3112 | _ForwardIterator |
| 3113 | basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first, |
| 3114 | _ForwardIterator __last) |
| 3115 | { |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3116 | __owns_one_state<_CharT>* __e = __end_; |
| 3117 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3118 | _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last); |
| 3119 | if (__temp == __first && __temp != __last) |
| 3120 | { |
| 3121 | switch (*__temp) |
| 3122 | { |
| 3123 | case '^': |
| 3124 | __push_l_anchor(); |
| 3125 | ++__temp; |
| 3126 | break; |
| 3127 | case '$': |
| 3128 | __push_r_anchor(); |
| 3129 | ++__temp; |
| 3130 | break; |
| 3131 | case '(': |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3132 | __push_begin_marked_subexpression(); |
| 3133 | unsigned __temp_count = __marked_count_; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3134 | ++__open_count_; |
| 3135 | __temp = __parse_extended_reg_exp(++__temp, __last); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3136 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3137 | if (__temp == __last || *__temp != ')') |
| 3138 | throw regex_error(regex_constants::error_paren); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3139 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3140 | __push_end_marked_subexpression(__temp_count); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3141 | --__open_count_; |
| 3142 | ++__temp; |
| 3143 | break; |
| 3144 | } |
| 3145 | } |
| 3146 | if (__temp != __first) |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3147 | __temp = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin+1, |
| 3148 | __marked_count_+1); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3149 | __first = __temp; |
| 3150 | return __first; |
| 3151 | } |
| 3152 | |
| 3153 | template <class _CharT, class _Traits> |
| 3154 | template <class _ForwardIterator> |
| 3155 | _ForwardIterator |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3156 | basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first, |
| 3157 | _ForwardIterator __last) |
| 3158 | { |
| 3159 | while (true) |
| 3160 | { |
| 3161 | _ForwardIterator __temp = __parse_simple_RE(__first, __last); |
| 3162 | if (__temp == __first) |
| 3163 | break; |
| 3164 | __first = __temp; |
| 3165 | } |
| 3166 | return __first; |
| 3167 | } |
| 3168 | |
| 3169 | template <class _CharT, class _Traits> |
| 3170 | template <class _ForwardIterator> |
| 3171 | _ForwardIterator |
| 3172 | basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first, |
| 3173 | _ForwardIterator __last) |
| 3174 | { |
| 3175 | if (__first != __last) |
| 3176 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3177 | __owns_one_state<_CharT>* __e = __end_; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3178 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3179 | _ForwardIterator __temp = __parse_nondupl_RE(__first, __last); |
| 3180 | if (__temp != __first) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3181 | __first = __parse_RE_dupl_symbol(__temp, __last, __e, |
| 3182 | __mexp_begin+1, __marked_count_+1); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3183 | } |
| 3184 | return __first; |
| 3185 | } |
| 3186 | |
| 3187 | template <class _CharT, class _Traits> |
| 3188 | template <class _ForwardIterator> |
| 3189 | _ForwardIterator |
| 3190 | basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first, |
| 3191 | _ForwardIterator __last) |
| 3192 | { |
| 3193 | _ForwardIterator __temp = __first; |
| 3194 | __first = __parse_one_char_or_coll_elem_RE(__first, __last); |
| 3195 | if (__temp == __first) |
| 3196 | { |
| 3197 | __temp = __parse_Back_open_paren(__first, __last); |
| 3198 | if (__temp != __first) |
| 3199 | { |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3200 | __push_begin_marked_subexpression(); |
| 3201 | unsigned __temp_count = __marked_count_; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3202 | __first = __parse_RE_expression(__temp, __last); |
| 3203 | __temp = __parse_Back_close_paren(__first, __last); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3204 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3205 | if (__temp == __first) |
| 3206 | throw regex_error(regex_constants::error_paren); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3207 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3208 | __push_end_marked_subexpression(__temp_count); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3209 | __first = __temp; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3210 | } |
| 3211 | else |
| 3212 | __first = __parse_BACKREF(__first, __last); |
| 3213 | } |
| 3214 | return __first; |
| 3215 | } |
| 3216 | |
| 3217 | template <class _CharT, class _Traits> |
| 3218 | template <class _ForwardIterator> |
| 3219 | _ForwardIterator |
| 3220 | basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE( |
| 3221 | _ForwardIterator __first, |
| 3222 | _ForwardIterator __last) |
| 3223 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3224 | _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3225 | if (__temp == __first) |
| 3226 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3227 | __temp = __parse_QUOTED_CHAR(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3228 | if (__temp == __first) |
| 3229 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3230 | if (__temp != __last && *__temp == '.') |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3231 | { |
| 3232 | __push_match_any(); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3233 | ++__temp; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3234 | } |
| 3235 | else |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3236 | __temp = __parse_bracket_expression(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3237 | } |
| 3238 | } |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3239 | __first = __temp; |
| 3240 | return __first; |
| 3241 | } |
| 3242 | |
| 3243 | template <class _CharT, class _Traits> |
| 3244 | template <class _ForwardIterator> |
| 3245 | _ForwardIterator |
| 3246 | basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE( |
| 3247 | _ForwardIterator __first, |
| 3248 | _ForwardIterator __last) |
| 3249 | { |
| 3250 | _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last); |
| 3251 | if (__temp == __first) |
| 3252 | { |
| 3253 | __temp = __parse_QUOTED_CHAR_ERE(__first, __last); |
| 3254 | if (__temp == __first) |
| 3255 | { |
| 3256 | if (__temp != __last && *__temp == '.') |
| 3257 | { |
| 3258 | __push_match_any(); |
| 3259 | ++__temp; |
| 3260 | } |
| 3261 | else |
| 3262 | __temp = __parse_bracket_expression(__first, __last); |
| 3263 | } |
| 3264 | } |
| 3265 | __first = __temp; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3266 | return __first; |
| 3267 | } |
| 3268 | |
| 3269 | template <class _CharT, class _Traits> |
| 3270 | template <class _ForwardIterator> |
| 3271 | _ForwardIterator |
| 3272 | basic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first, |
| 3273 | _ForwardIterator __last) |
| 3274 | { |
| 3275 | if (__first != __last) |
| 3276 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3277 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3278 | if (__temp != __last) |
| 3279 | { |
| 3280 | if (*__first == '\\' && *__temp == '(') |
| 3281 | __first = ++__temp; |
| 3282 | } |
| 3283 | } |
| 3284 | return __first; |
| 3285 | } |
| 3286 | |
| 3287 | template <class _CharT, class _Traits> |
| 3288 | template <class _ForwardIterator> |
| 3289 | _ForwardIterator |
| 3290 | basic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first, |
| 3291 | _ForwardIterator __last) |
| 3292 | { |
| 3293 | if (__first != __last) |
| 3294 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3295 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3296 | if (__temp != __last) |
| 3297 | { |
| 3298 | if (*__first == '\\' && *__temp == ')') |
| 3299 | __first = ++__temp; |
| 3300 | } |
| 3301 | } |
| 3302 | return __first; |
| 3303 | } |
| 3304 | |
| 3305 | template <class _CharT, class _Traits> |
| 3306 | template <class _ForwardIterator> |
| 3307 | _ForwardIterator |
| 3308 | basic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first, |
| 3309 | _ForwardIterator __last) |
| 3310 | { |
| 3311 | if (__first != __last) |
| 3312 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3313 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3314 | if (__temp != __last) |
| 3315 | { |
| 3316 | if (*__first == '\\' && *__temp == '{') |
| 3317 | __first = ++__temp; |
| 3318 | } |
| 3319 | } |
| 3320 | return __first; |
| 3321 | } |
| 3322 | |
| 3323 | template <class _CharT, class _Traits> |
| 3324 | template <class _ForwardIterator> |
| 3325 | _ForwardIterator |
| 3326 | basic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first, |
| 3327 | _ForwardIterator __last) |
| 3328 | { |
| 3329 | if (__first != __last) |
| 3330 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3331 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3332 | if (__temp != __last) |
| 3333 | { |
| 3334 | if (*__first == '\\' && *__temp == '}') |
| 3335 | __first = ++__temp; |
| 3336 | } |
| 3337 | } |
| 3338 | return __first; |
| 3339 | } |
| 3340 | |
| 3341 | template <class _CharT, class _Traits> |
| 3342 | template <class _ForwardIterator> |
| 3343 | _ForwardIterator |
| 3344 | basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first, |
| 3345 | _ForwardIterator __last) |
| 3346 | { |
| 3347 | if (__first != __last) |
| 3348 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3349 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3350 | if (__temp != __last) |
| 3351 | { |
Marshall Clow | 97f50f6 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 3352 | if (*__first == '\\') |
| 3353 | { |
| 3354 | int __val = __traits_.value(*__temp, 10); |
| 3355 | if (__val >= 1 && __val <= 9) |
| 3356 | { |
| 3357 | __push_back_ref(__val); |
| 3358 | __first = ++__temp; |
| 3359 | } |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3360 | } |
| 3361 | } |
| 3362 | } |
| 3363 | return __first; |
| 3364 | } |
| 3365 | |
| 3366 | template <class _CharT, class _Traits> |
| 3367 | template <class _ForwardIterator> |
| 3368 | _ForwardIterator |
| 3369 | basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first, |
| 3370 | _ForwardIterator __last) |
| 3371 | { |
| 3372 | if (__first != __last) |
| 3373 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3374 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3375 | if (__temp == __last && *__first == '$') |
| 3376 | return __first; |
| 3377 | // Not called inside a bracket |
| 3378 | if (*__first == '.' || *__first == '\\' || *__first == '[') |
| 3379 | return __first; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3380 | __push_char(*__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3381 | ++__first; |
| 3382 | } |
| 3383 | return __first; |
| 3384 | } |
| 3385 | |
| 3386 | template <class _CharT, class _Traits> |
| 3387 | template <class _ForwardIterator> |
| 3388 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3389 | basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first, |
| 3390 | _ForwardIterator __last) |
| 3391 | { |
| 3392 | if (__first != __last) |
| 3393 | { |
| 3394 | switch (*__first) |
| 3395 | { |
| 3396 | case '^': |
| 3397 | case '.': |
| 3398 | case '[': |
| 3399 | case '$': |
| 3400 | case '(': |
| 3401 | case '|': |
| 3402 | case '*': |
| 3403 | case '+': |
| 3404 | case '?': |
| 3405 | case '{': |
| 3406 | case '\\': |
| 3407 | break; |
| 3408 | case ')': |
| 3409 | if (__open_count_ == 0) |
| 3410 | { |
| 3411 | __push_char(*__first); |
| 3412 | ++__first; |
| 3413 | } |
| 3414 | break; |
| 3415 | default: |
| 3416 | __push_char(*__first); |
| 3417 | ++__first; |
| 3418 | break; |
| 3419 | } |
| 3420 | } |
| 3421 | return __first; |
| 3422 | } |
| 3423 | |
| 3424 | template <class _CharT, class _Traits> |
| 3425 | template <class _ForwardIterator> |
| 3426 | _ForwardIterator |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3427 | basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first, |
| 3428 | _ForwardIterator __last) |
| 3429 | { |
| 3430 | if (__first != __last) |
| 3431 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3432 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3433 | if (__temp != __last) |
| 3434 | { |
| 3435 | if (*__first == '\\') |
| 3436 | { |
| 3437 | switch (*__temp) |
| 3438 | { |
| 3439 | case '^': |
| 3440 | case '.': |
| 3441 | case '*': |
| 3442 | case '[': |
| 3443 | case '$': |
| 3444 | case '\\': |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3445 | __push_char(*__temp); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3446 | __first = ++__temp; |
| 3447 | break; |
| 3448 | } |
| 3449 | } |
| 3450 | } |
| 3451 | } |
| 3452 | return __first; |
| 3453 | } |
| 3454 | |
| 3455 | template <class _CharT, class _Traits> |
| 3456 | template <class _ForwardIterator> |
| 3457 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3458 | basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first, |
| 3459 | _ForwardIterator __last) |
| 3460 | { |
| 3461 | if (__first != __last) |
| 3462 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3463 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3464 | if (__temp != __last) |
| 3465 | { |
| 3466 | if (*__first == '\\') |
| 3467 | { |
| 3468 | switch (*__temp) |
| 3469 | { |
| 3470 | case '^': |
| 3471 | case '.': |
| 3472 | case '*': |
| 3473 | case '[': |
| 3474 | case '$': |
| 3475 | case '\\': |
| 3476 | case '(': |
| 3477 | case ')': |
| 3478 | case '|': |
| 3479 | case '+': |
| 3480 | case '?': |
| 3481 | case '{': |
Howard Hinnant | c1ecd97 | 2013-06-28 20:31:05 +0000 | [diff] [blame] | 3482 | case '}': |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3483 | __push_char(*__temp); |
| 3484 | __first = ++__temp; |
| 3485 | break; |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3486 | default: |
| 3487 | if ((__flags_ & 0x1F0) == awk) |
| 3488 | __first = __parse_awk_escape(++__first, __last); |
| 3489 | break; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3490 | } |
| 3491 | } |
| 3492 | } |
| 3493 | } |
| 3494 | return __first; |
| 3495 | } |
| 3496 | |
| 3497 | template <class _CharT, class _Traits> |
| 3498 | template <class _ForwardIterator> |
| 3499 | _ForwardIterator |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3500 | basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3501 | _ForwardIterator __last, |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3502 | __owns_one_state<_CharT>* __s, |
| 3503 | unsigned __mexp_begin, |
| 3504 | unsigned __mexp_end) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3505 | { |
| 3506 | if (__first != __last) |
| 3507 | { |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3508 | if (*__first == '*') |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3509 | { |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3510 | __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3511 | ++__first; |
| 3512 | } |
| 3513 | else |
| 3514 | { |
| 3515 | _ForwardIterator __temp = __parse_Back_open_brace(__first, __last); |
| 3516 | if (__temp != __first) |
| 3517 | { |
| 3518 | int __min = 0; |
| 3519 | __first = __temp; |
| 3520 | __temp = __parse_DUP_COUNT(__first, __last, __min); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3521 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3522 | if (__temp == __first) |
| 3523 | throw regex_error(regex_constants::error_badbrace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3524 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3525 | __first = __temp; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3526 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3527 | if (__first == __last) |
| 3528 | throw regex_error(regex_constants::error_brace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3529 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3530 | if (*__first != ',') |
| 3531 | { |
| 3532 | __temp = __parse_Back_close_brace(__first, __last); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3533 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3534 | if (__temp == __first) |
| 3535 | throw regex_error(regex_constants::error_brace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3536 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 3537 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, |
| 3538 | true); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3539 | __first = __temp; |
| 3540 | } |
| 3541 | else |
| 3542 | { |
| 3543 | ++__first; // consume ',' |
| 3544 | int __max = -1; |
| 3545 | __first = __parse_DUP_COUNT(__first, __last, __max); |
| 3546 | __temp = __parse_Back_close_brace(__first, __last); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3547 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3548 | if (__temp == __first) |
| 3549 | throw regex_error(regex_constants::error_brace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3550 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3551 | if (__max == -1) |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3552 | __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3553 | else |
| 3554 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3555 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3556 | if (__max < __min) |
| 3557 | throw regex_error(regex_constants::error_badbrace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3558 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 3559 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, |
| 3560 | true); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3561 | } |
| 3562 | __first = __temp; |
| 3563 | } |
| 3564 | } |
| 3565 | } |
| 3566 | } |
| 3567 | return __first; |
| 3568 | } |
| 3569 | |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3570 | template <class _CharT, class _Traits> |
| 3571 | template <class _ForwardIterator> |
| 3572 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3573 | basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first, |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3574 | _ForwardIterator __last, |
| 3575 | __owns_one_state<_CharT>* __s, |
| 3576 | unsigned __mexp_begin, |
| 3577 | unsigned __mexp_end) |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3578 | { |
| 3579 | if (__first != __last) |
| 3580 | { |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3581 | unsigned __grammar = __flags_ & 0x1F0; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3582 | switch (*__first) |
| 3583 | { |
| 3584 | case '*': |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3585 | ++__first; |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3586 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3587 | { |
| 3588 | ++__first; |
| 3589 | __push_nongreedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
| 3590 | } |
| 3591 | else |
| 3592 | __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3593 | break; |
| 3594 | case '+': |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3595 | ++__first; |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3596 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3597 | { |
| 3598 | ++__first; |
| 3599 | __push_nongreedy_inf_repeat(1, __s, __mexp_begin, __mexp_end); |
| 3600 | } |
| 3601 | else |
| 3602 | __push_greedy_inf_repeat(1, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3603 | break; |
| 3604 | case '?': |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3605 | ++__first; |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3606 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3607 | { |
| 3608 | ++__first; |
| 3609 | __push_loop(0, 1, __s, __mexp_begin, __mexp_end, false); |
| 3610 | } |
| 3611 | else |
| 3612 | __push_loop(0, 1, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3613 | break; |
| 3614 | case '{': |
| 3615 | { |
| 3616 | int __min; |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3617 | _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3618 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3619 | if (__temp == __first) |
| 3620 | throw regex_error(regex_constants::error_badbrace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3621 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3622 | __first = __temp; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3623 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3624 | if (__first == __last) |
| 3625 | throw regex_error(regex_constants::error_brace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3626 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3627 | switch (*__first) |
| 3628 | { |
| 3629 | case '}': |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3630 | ++__first; |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3631 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3632 | { |
| 3633 | ++__first; |
| 3634 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, false); |
| 3635 | } |
| 3636 | else |
| 3637 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3638 | break; |
| 3639 | case ',': |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3640 | ++__first; |
| 3641 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3642 | if (__first == __last) |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3643 | throw regex_error(regex_constants::error_badbrace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3644 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3645 | if (*__first == '}') |
| 3646 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3647 | ++__first; |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3648 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3649 | { |
| 3650 | ++__first; |
| 3651 | __push_nongreedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
| 3652 | } |
| 3653 | else |
| 3654 | __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3655 | } |
| 3656 | else |
| 3657 | { |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3658 | int __max = -1; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3659 | __temp = __parse_DUP_COUNT(__first, __last, __max); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3660 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3661 | if (__temp == __first) |
| 3662 | throw regex_error(regex_constants::error_brace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3663 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3664 | __first = __temp; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3665 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3666 | if (__first == __last || *__first != '}') |
| 3667 | throw regex_error(regex_constants::error_brace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3668 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3669 | ++__first; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3670 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3671 | if (__max < __min) |
| 3672 | throw regex_error(regex_constants::error_badbrace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3673 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3674 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3675 | { |
| 3676 | ++__first; |
| 3677 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, false); |
| 3678 | } |
| 3679 | else |
| 3680 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3681 | } |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3682 | break; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3683 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3684 | default: |
| 3685 | throw regex_error(regex_constants::error_badbrace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3686 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3687 | } |
| 3688 | } |
| 3689 | break; |
| 3690 | } |
| 3691 | } |
| 3692 | return __first; |
| 3693 | } |
| 3694 | |
| 3695 | template <class _CharT, class _Traits> |
| 3696 | template <class _ForwardIterator> |
| 3697 | _ForwardIterator |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3698 | basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first, |
| 3699 | _ForwardIterator __last) |
| 3700 | { |
| 3701 | if (__first != __last && *__first == '[') |
| 3702 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3703 | ++__first; |
| 3704 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3705 | if (__first == __last) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3706 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3707 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3708 | bool __negate = false; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3709 | if (*__first == '^') |
| 3710 | { |
| 3711 | ++__first; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3712 | __negate = true; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3713 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3714 | __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate); |
| 3715 | // __ml owned by *this |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3716 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3717 | if (__first == __last) |
| 3718 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3719 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3720 | if ((__flags_ & 0x1F0) != ECMAScript && *__first == ']') |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3721 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3722 | __ml->__add_char(']'); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3723 | ++__first; |
| 3724 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3725 | __first = __parse_follow_list(__first, __last, __ml); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3726 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3727 | if (__first == __last) |
| 3728 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3729 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3730 | if (*__first == '-') |
| 3731 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3732 | __ml->__add_char('-'); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3733 | ++__first; |
| 3734 | } |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3735 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3736 | if (__first == __last || *__first != ']') |
| 3737 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3738 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3739 | ++__first; |
| 3740 | } |
| 3741 | return __first; |
| 3742 | } |
| 3743 | |
| 3744 | template <class _CharT, class _Traits> |
| 3745 | template <class _ForwardIterator> |
| 3746 | _ForwardIterator |
| 3747 | basic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3748 | _ForwardIterator __last, |
| 3749 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3750 | { |
| 3751 | if (__first != __last) |
| 3752 | { |
| 3753 | while (true) |
| 3754 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3755 | _ForwardIterator __temp = __parse_expression_term(__first, __last, |
| 3756 | __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3757 | if (__temp == __first) |
| 3758 | break; |
| 3759 | __first = __temp; |
| 3760 | } |
| 3761 | } |
| 3762 | return __first; |
| 3763 | } |
| 3764 | |
| 3765 | template <class _CharT, class _Traits> |
| 3766 | template <class _ForwardIterator> |
| 3767 | _ForwardIterator |
| 3768 | basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3769 | _ForwardIterator __last, |
| 3770 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3771 | { |
| 3772 | if (__first != __last && *__first != ']') |
| 3773 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3774 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3775 | basic_string<_CharT> __start_range; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3776 | if (__temp != __last && *__first == '[') |
| 3777 | { |
| 3778 | if (*__temp == '=') |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3779 | return __parse_equivalence_class(++__temp, __last, __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3780 | else if (*__temp == ':') |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3781 | return __parse_character_class(++__temp, __last, __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3782 | else if (*__temp == '.') |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3783 | __first = __parse_collating_symbol(++__temp, __last, __start_range); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3784 | } |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3785 | unsigned __grammar = __flags_ & 0x1F0; |
| 3786 | if (__start_range.empty()) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3787 | { |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3788 | if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') |
| 3789 | { |
| 3790 | if (__grammar == ECMAScript) |
| 3791 | __first = __parse_class_escape(++__first, __last, __start_range, __ml); |
| 3792 | else |
| 3793 | __first = __parse_awk_escape(++__first, __last, &__start_range); |
| 3794 | } |
| 3795 | else |
| 3796 | { |
| 3797 | __start_range = *__first; |
| 3798 | ++__first; |
| 3799 | } |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3800 | } |
| 3801 | if (__first != __last && *__first != ']') |
| 3802 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3803 | __temp = _VSTD::next(__first); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3804 | if (__temp != __last && *__first == '-' && *__temp != ']') |
| 3805 | { |
| 3806 | // parse a range |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3807 | basic_string<_CharT> __end_range; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3808 | __first = __temp; |
| 3809 | ++__temp; |
| 3810 | if (__temp != __last && *__first == '[' && *__temp == '.') |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3811 | __first = __parse_collating_symbol(++__temp, __last, __end_range); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3812 | else |
| 3813 | { |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3814 | if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') |
| 3815 | { |
| 3816 | if (__grammar == ECMAScript) |
| 3817 | __first = __parse_class_escape(++__first, __last, |
| 3818 | __end_range, __ml); |
| 3819 | else |
| 3820 | __first = __parse_awk_escape(++__first, __last, |
| 3821 | &__end_range); |
| 3822 | } |
| 3823 | else |
| 3824 | { |
| 3825 | __end_range = *__first; |
| 3826 | ++__first; |
| 3827 | } |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3828 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3829 | __ml->__add_range(_VSTD::move(__start_range), _VSTD::move(__end_range)); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3830 | } |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3831 | else if (!__start_range.empty()) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3832 | { |
| 3833 | if (__start_range.size() == 1) |
| 3834 | __ml->__add_char(__start_range[0]); |
| 3835 | else |
| 3836 | __ml->__add_digraph(__start_range[0], __start_range[1]); |
| 3837 | } |
| 3838 | } |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3839 | else if (!__start_range.empty()) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3840 | { |
| 3841 | if (__start_range.size() == 1) |
| 3842 | __ml->__add_char(__start_range[0]); |
| 3843 | else |
| 3844 | __ml->__add_digraph(__start_range[0], __start_range[1]); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3845 | } |
| 3846 | } |
| 3847 | return __first; |
| 3848 | } |
| 3849 | |
| 3850 | template <class _CharT, class _Traits> |
| 3851 | template <class _ForwardIterator> |
| 3852 | _ForwardIterator |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3853 | basic_regex<_CharT, _Traits>::__parse_class_escape(_ForwardIterator __first, |
| 3854 | _ForwardIterator __last, |
| 3855 | basic_string<_CharT>& __str, |
| 3856 | __bracket_expression<_CharT, _Traits>* __ml) |
| 3857 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3858 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3859 | if (__first == __last) |
| 3860 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3861 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3862 | switch (*__first) |
| 3863 | { |
| 3864 | case 0: |
| 3865 | __str = *__first; |
| 3866 | return ++__first; |
| 3867 | case 'b': |
| 3868 | __str = _CharT(8); |
| 3869 | return ++__first; |
| 3870 | case 'd': |
| 3871 | __ml->__add_class(ctype_base::digit); |
| 3872 | return ++__first; |
| 3873 | case 'D': |
| 3874 | __ml->__add_neg_class(ctype_base::digit); |
| 3875 | return ++__first; |
| 3876 | case 's': |
| 3877 | __ml->__add_class(ctype_base::space); |
| 3878 | return ++__first; |
| 3879 | case 'S': |
| 3880 | __ml->__add_neg_class(ctype_base::space); |
| 3881 | return ++__first; |
| 3882 | case 'w': |
| 3883 | __ml->__add_class(ctype_base::alnum); |
| 3884 | __ml->__add_char('_'); |
| 3885 | return ++__first; |
| 3886 | case 'W': |
| 3887 | __ml->__add_neg_class(ctype_base::alnum); |
| 3888 | __ml->__add_neg_char('_'); |
| 3889 | return ++__first; |
| 3890 | } |
| 3891 | __first = __parse_character_escape(__first, __last, &__str); |
| 3892 | return __first; |
| 3893 | } |
| 3894 | |
| 3895 | template <class _CharT, class _Traits> |
| 3896 | template <class _ForwardIterator> |
| 3897 | _ForwardIterator |
| 3898 | basic_regex<_CharT, _Traits>::__parse_awk_escape(_ForwardIterator __first, |
| 3899 | _ForwardIterator __last, |
| 3900 | basic_string<_CharT>* __str) |
| 3901 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3902 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3903 | if (__first == __last) |
| 3904 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3905 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3906 | switch (*__first) |
| 3907 | { |
| 3908 | case '\\': |
| 3909 | case '"': |
| 3910 | case '/': |
| 3911 | if (__str) |
| 3912 | *__str = *__first; |
| 3913 | else |
| 3914 | __push_char(*__first); |
| 3915 | return ++__first; |
| 3916 | case 'a': |
| 3917 | if (__str) |
| 3918 | *__str = _CharT(7); |
| 3919 | else |
| 3920 | __push_char(_CharT(7)); |
| 3921 | return ++__first; |
| 3922 | case 'b': |
| 3923 | if (__str) |
| 3924 | *__str = _CharT(8); |
| 3925 | else |
| 3926 | __push_char(_CharT(8)); |
| 3927 | return ++__first; |
| 3928 | case 'f': |
| 3929 | if (__str) |
| 3930 | *__str = _CharT(0xC); |
| 3931 | else |
| 3932 | __push_char(_CharT(0xC)); |
| 3933 | return ++__first; |
| 3934 | case 'n': |
| 3935 | if (__str) |
| 3936 | *__str = _CharT(0xA); |
| 3937 | else |
| 3938 | __push_char(_CharT(0xA)); |
| 3939 | return ++__first; |
| 3940 | case 'r': |
| 3941 | if (__str) |
| 3942 | *__str = _CharT(0xD); |
| 3943 | else |
| 3944 | __push_char(_CharT(0xD)); |
| 3945 | return ++__first; |
| 3946 | case 't': |
| 3947 | if (__str) |
| 3948 | *__str = _CharT(0x9); |
| 3949 | else |
| 3950 | __push_char(_CharT(0x9)); |
| 3951 | return ++__first; |
| 3952 | case 'v': |
| 3953 | if (__str) |
| 3954 | *__str = _CharT(0xB); |
| 3955 | else |
| 3956 | __push_char(_CharT(0xB)); |
| 3957 | return ++__first; |
| 3958 | } |
| 3959 | if ('0' <= *__first && *__first <= '7') |
| 3960 | { |
| 3961 | unsigned __val = *__first - '0'; |
| 3962 | if (++__first != __last && ('0' <= *__first && *__first <= '7')) |
| 3963 | { |
| 3964 | __val = 8 * __val + *__first - '0'; |
| 3965 | if (++__first != __last && ('0' <= *__first && *__first <= '7')) |
Howard Hinnant | dbc8cf0 | 2013-07-02 17:43:31 +0000 | [diff] [blame] | 3966 | __val = 8 * __val + *__first++ - '0'; |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3967 | } |
| 3968 | if (__str) |
| 3969 | *__str = _CharT(__val); |
| 3970 | else |
| 3971 | __push_char(_CharT(__val)); |
| 3972 | } |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3973 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3974 | else |
| 3975 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3976 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3977 | return __first; |
| 3978 | } |
| 3979 | |
| 3980 | template <class _CharT, class _Traits> |
| 3981 | template <class _ForwardIterator> |
| 3982 | _ForwardIterator |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3983 | basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3984 | _ForwardIterator __last, |
| 3985 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3986 | { |
| 3987 | // Found [= |
| 3988 | // This means =] must exist |
| 3989 | value_type _Equal_close[2] = {'=', ']'}; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3990 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Equal_close, |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3991 | _Equal_close+2); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3992 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3993 | if (__temp == __last) |
| 3994 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3995 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3996 | // [__first, __temp) contains all text in [= ... =] |
| 3997 | typedef typename _Traits::string_type string_type; |
| 3998 | string_type __collate_name = |
| 3999 | __traits_.lookup_collatename(__first, __temp); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4000 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4001 | if (__collate_name.empty()) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4002 | throw regex_error(regex_constants::error_collate); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4003 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4004 | string_type __equiv_name = |
| 4005 | __traits_.transform_primary(__collate_name.begin(), |
| 4006 | __collate_name.end()); |
| 4007 | if (!__equiv_name.empty()) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4008 | __ml->__add_equivalence(__equiv_name); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4009 | else |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4010 | { |
| 4011 | switch (__collate_name.size()) |
| 4012 | { |
| 4013 | case 1: |
| 4014 | __ml->__add_char(__collate_name[0]); |
| 4015 | break; |
| 4016 | case 2: |
| 4017 | __ml->__add_digraph(__collate_name[0], __collate_name[1]); |
| 4018 | break; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4019 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4020 | default: |
| 4021 | throw regex_error(regex_constants::error_collate); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4022 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4023 | } |
| 4024 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4025 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4026 | return __first; |
| 4027 | } |
| 4028 | |
| 4029 | template <class _CharT, class _Traits> |
| 4030 | template <class _ForwardIterator> |
| 4031 | _ForwardIterator |
| 4032 | basic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4033 | _ForwardIterator __last, |
| 4034 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4035 | { |
| 4036 | // Found [: |
| 4037 | // This means :] must exist |
| 4038 | value_type _Colon_close[2] = {':', ']'}; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4039 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Colon_close, |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4040 | _Colon_close+2); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4041 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4042 | if (__temp == __last) |
| 4043 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4044 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4045 | // [__first, __temp) contains all text in [: ... :] |
| 4046 | typedef typename _Traits::char_class_type char_class_type; |
| 4047 | char_class_type __class_type = |
| 4048 | __traits_.lookup_classname(__first, __temp, __flags_ & icase); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4049 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4050 | if (__class_type == 0) |
| 4051 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4052 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4053 | __ml->__add_class(__class_type); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4054 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4055 | return __first; |
| 4056 | } |
| 4057 | |
| 4058 | template <class _CharT, class _Traits> |
| 4059 | template <class _ForwardIterator> |
| 4060 | _ForwardIterator |
| 4061 | basic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4062 | _ForwardIterator __last, |
| 4063 | basic_string<_CharT>& __col_sym) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4064 | { |
| 4065 | // Found [. |
| 4066 | // This means .] must exist |
| 4067 | value_type _Dot_close[2] = {'.', ']'}; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4068 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Dot_close, |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4069 | _Dot_close+2); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4070 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4071 | if (__temp == __last) |
| 4072 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4073 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4074 | // [__first, __temp) contains all text in [. ... .] |
| 4075 | typedef typename _Traits::string_type string_type; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4076 | __col_sym = __traits_.lookup_collatename(__first, __temp); |
| 4077 | switch (__col_sym.size()) |
| 4078 | { |
| 4079 | case 1: |
| 4080 | case 2: |
| 4081 | break; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4082 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4083 | default: |
| 4084 | throw regex_error(regex_constants::error_collate); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4085 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4086 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4087 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4088 | return __first; |
| 4089 | } |
| 4090 | |
| 4091 | template <class _CharT, class _Traits> |
| 4092 | template <class _ForwardIterator> |
| 4093 | _ForwardIterator |
| 4094 | basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first, |
| 4095 | _ForwardIterator __last, |
| 4096 | int& __c) |
| 4097 | { |
Marshall Clow | 97f50f6 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4098 | if (__first != __last ) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4099 | { |
Marshall Clow | 97f50f6 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4100 | int __val = __traits_.value(*__first, 10); |
| 4101 | if ( __val != -1 ) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4102 | { |
Marshall Clow | 97f50f6 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4103 | __c = __val; |
| 4104 | for (++__first; |
| 4105 | __first != __last && ( __val = __traits_.value(*__first, 10)) != -1; |
| 4106 | ++__first) |
| 4107 | { |
| 4108 | __c *= 10; |
| 4109 | __c += __val; |
| 4110 | } |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4111 | } |
| 4112 | } |
| 4113 | return __first; |
| 4114 | } |
| 4115 | |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4116 | template <class _CharT, class _Traits> |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4117 | template <class _ForwardIterator> |
| 4118 | _ForwardIterator |
| 4119 | basic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first, |
| 4120 | _ForwardIterator __last) |
| 4121 | { |
| 4122 | __owns_one_state<_CharT>* __sa = __end_; |
| 4123 | _ForwardIterator __temp = __parse_alternative(__first, __last); |
| 4124 | if (__temp == __first) |
| 4125 | __push_empty(); |
| 4126 | __first = __temp; |
| 4127 | while (__first != __last && *__first == '|') |
| 4128 | { |
| 4129 | __owns_one_state<_CharT>* __sb = __end_; |
| 4130 | __temp = __parse_alternative(++__first, __last); |
| 4131 | if (__temp == __first) |
| 4132 | __push_empty(); |
| 4133 | __push_alternation(__sa, __sb); |
| 4134 | __first = __temp; |
| 4135 | } |
| 4136 | return __first; |
| 4137 | } |
| 4138 | |
| 4139 | template <class _CharT, class _Traits> |
| 4140 | template <class _ForwardIterator> |
| 4141 | _ForwardIterator |
| 4142 | basic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first, |
| 4143 | _ForwardIterator __last) |
| 4144 | { |
| 4145 | while (true) |
| 4146 | { |
| 4147 | _ForwardIterator __temp = __parse_term(__first, __last); |
| 4148 | if (__temp == __first) |
| 4149 | break; |
| 4150 | __first = __temp; |
| 4151 | } |
| 4152 | return __first; |
| 4153 | } |
| 4154 | |
| 4155 | template <class _CharT, class _Traits> |
| 4156 | template <class _ForwardIterator> |
| 4157 | _ForwardIterator |
| 4158 | basic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first, |
| 4159 | _ForwardIterator __last) |
| 4160 | { |
| 4161 | _ForwardIterator __temp = __parse_assertion(__first, __last); |
| 4162 | if (__temp == __first) |
| 4163 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4164 | __owns_one_state<_CharT>* __e = __end_; |
| 4165 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4166 | __temp = __parse_atom(__first, __last); |
| 4167 | if (__temp != __first) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4168 | __first = __parse_ERE_dupl_symbol(__temp, __last, __e, |
| 4169 | __mexp_begin+1, __marked_count_+1); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4170 | } |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4171 | else |
| 4172 | __first = __temp; |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4173 | return __first; |
| 4174 | } |
| 4175 | |
| 4176 | template <class _CharT, class _Traits> |
| 4177 | template <class _ForwardIterator> |
| 4178 | _ForwardIterator |
| 4179 | basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first, |
| 4180 | _ForwardIterator __last) |
| 4181 | { |
| 4182 | if (__first != __last) |
| 4183 | { |
| 4184 | switch (*__first) |
| 4185 | { |
| 4186 | case '^': |
| 4187 | __push_l_anchor(); |
| 4188 | ++__first; |
| 4189 | break; |
| 4190 | case '$': |
| 4191 | __push_r_anchor(); |
| 4192 | ++__first; |
| 4193 | break; |
| 4194 | case '\\': |
| 4195 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4196 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4197 | if (__temp != __last) |
| 4198 | { |
| 4199 | if (*__temp == 'b') |
| 4200 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4201 | __push_word_boundary(false); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4202 | __first = ++__temp; |
| 4203 | } |
| 4204 | else if (*__temp == 'B') |
| 4205 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4206 | __push_word_boundary(true); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4207 | __first = ++__temp; |
| 4208 | } |
| 4209 | } |
| 4210 | } |
| 4211 | break; |
| 4212 | case '(': |
| 4213 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4214 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4215 | if (__temp != __last && *__temp == '?') |
| 4216 | { |
| 4217 | if (++__temp != __last) |
| 4218 | { |
| 4219 | switch (*__temp) |
| 4220 | { |
| 4221 | case '=': |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4222 | { |
| 4223 | basic_regex __exp; |
| 4224 | __exp.__flags_ = __flags_; |
| 4225 | __temp = __exp.__parse(++__temp, __last); |
Howard Hinnant | cd59acc | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 4226 | unsigned __mexp = __exp.__marked_count_; |
| 4227 | __push_lookahead(_VSTD::move(__exp), false, __marked_count_); |
| 4228 | __marked_count_ += __mexp; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4229 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4230 | if (__temp == __last || *__temp != ')') |
| 4231 | throw regex_error(regex_constants::error_paren); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4232 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4233 | __first = ++__temp; |
| 4234 | } |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4235 | break; |
| 4236 | case '!': |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4237 | { |
| 4238 | basic_regex __exp; |
| 4239 | __exp.__flags_ = __flags_; |
| 4240 | __temp = __exp.__parse(++__temp, __last); |
Howard Hinnant | cd59acc | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 4241 | unsigned __mexp = __exp.__marked_count_; |
| 4242 | __push_lookahead(_VSTD::move(__exp), true, __marked_count_); |
| 4243 | __marked_count_ += __mexp; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4244 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4245 | if (__temp == __last || *__temp != ')') |
| 4246 | throw regex_error(regex_constants::error_paren); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4247 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4248 | __first = ++__temp; |
| 4249 | } |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4250 | break; |
| 4251 | } |
| 4252 | } |
| 4253 | } |
| 4254 | } |
| 4255 | break; |
| 4256 | } |
| 4257 | } |
| 4258 | return __first; |
| 4259 | } |
| 4260 | |
| 4261 | template <class _CharT, class _Traits> |
| 4262 | template <class _ForwardIterator> |
| 4263 | _ForwardIterator |
| 4264 | basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first, |
| 4265 | _ForwardIterator __last) |
| 4266 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4267 | if (__first != __last) |
| 4268 | { |
| 4269 | switch (*__first) |
| 4270 | { |
| 4271 | case '.': |
| 4272 | __push_match_any_but_newline(); |
| 4273 | ++__first; |
| 4274 | break; |
| 4275 | case '\\': |
| 4276 | __first = __parse_atom_escape(__first, __last); |
| 4277 | break; |
| 4278 | case '[': |
| 4279 | __first = __parse_bracket_expression(__first, __last); |
| 4280 | break; |
| 4281 | case '(': |
| 4282 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4283 | ++__first; |
| 4284 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4285 | if (__first == __last) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4286 | throw regex_error(regex_constants::error_paren); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4287 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4288 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4289 | if (__temp != __last && *__first == '?' && *__temp == ':') |
| 4290 | { |
| 4291 | ++__open_count_; |
| 4292 | __first = __parse_ecma_exp(++__temp, __last); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4293 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4294 | if (__first == __last || *__first != ')') |
| 4295 | throw regex_error(regex_constants::error_paren); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4296 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4297 | --__open_count_; |
| 4298 | ++__first; |
| 4299 | } |
| 4300 | else |
| 4301 | { |
| 4302 | __push_begin_marked_subexpression(); |
| 4303 | unsigned __temp_count = __marked_count_; |
| 4304 | ++__open_count_; |
| 4305 | __first = __parse_ecma_exp(__first, __last); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4306 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4307 | if (__first == __last || *__first != ')') |
| 4308 | throw regex_error(regex_constants::error_paren); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4309 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4310 | __push_end_marked_subexpression(__temp_count); |
| 4311 | --__open_count_; |
| 4312 | ++__first; |
| 4313 | } |
| 4314 | } |
| 4315 | break; |
| 4316 | default: |
| 4317 | __first = __parse_pattern_character(__first, __last); |
| 4318 | break; |
| 4319 | } |
| 4320 | } |
| 4321 | return __first; |
| 4322 | } |
| 4323 | |
| 4324 | template <class _CharT, class _Traits> |
| 4325 | template <class _ForwardIterator> |
| 4326 | _ForwardIterator |
| 4327 | basic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first, |
| 4328 | _ForwardIterator __last) |
| 4329 | { |
| 4330 | if (__first != __last && *__first == '\\') |
| 4331 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4332 | _ForwardIterator __t1 = _VSTD::next(__first); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4333 | _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last); |
| 4334 | if (__t2 != __t1) |
| 4335 | __first = __t2; |
| 4336 | else |
| 4337 | { |
| 4338 | __t2 = __parse_character_class_escape(__t1, __last); |
| 4339 | if (__t2 != __t1) |
| 4340 | __first = __t2; |
| 4341 | else |
| 4342 | { |
| 4343 | __t2 = __parse_character_escape(__t1, __last); |
| 4344 | if (__t2 != __t1) |
| 4345 | __first = __t2; |
| 4346 | } |
| 4347 | } |
| 4348 | } |
| 4349 | return __first; |
| 4350 | } |
| 4351 | |
| 4352 | template <class _CharT, class _Traits> |
| 4353 | template <class _ForwardIterator> |
| 4354 | _ForwardIterator |
| 4355 | basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first, |
| 4356 | _ForwardIterator __last) |
| 4357 | { |
| 4358 | if (__first != __last) |
| 4359 | { |
| 4360 | if (*__first == '0') |
| 4361 | { |
| 4362 | __push_char(_CharT()); |
| 4363 | ++__first; |
| 4364 | } |
| 4365 | else if ('1' <= *__first && *__first <= '9') |
| 4366 | { |
| 4367 | unsigned __v = *__first - '0'; |
| 4368 | for (++__first; '0' <= *__first && *__first <= '9'; ++__first) |
| 4369 | __v = 10 * __v + *__first - '0'; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4370 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4371 | if (__v > mark_count()) |
| 4372 | throw regex_error(regex_constants::error_backref); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4373 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4374 | __push_back_ref(__v); |
| 4375 | } |
| 4376 | } |
| 4377 | return __first; |
| 4378 | } |
| 4379 | |
| 4380 | template <class _CharT, class _Traits> |
| 4381 | template <class _ForwardIterator> |
| 4382 | _ForwardIterator |
| 4383 | basic_regex<_CharT, _Traits>::__parse_character_class_escape(_ForwardIterator __first, |
| 4384 | _ForwardIterator __last) |
| 4385 | { |
| 4386 | if (__first != __last) |
| 4387 | { |
| 4388 | __bracket_expression<_CharT, _Traits>* __ml; |
| 4389 | switch (*__first) |
| 4390 | { |
| 4391 | case 'd': |
| 4392 | __ml = __start_matching_list(false); |
| 4393 | __ml->__add_class(ctype_base::digit); |
| 4394 | ++__first; |
| 4395 | break; |
| 4396 | case 'D': |
| 4397 | __ml = __start_matching_list(true); |
| 4398 | __ml->__add_class(ctype_base::digit); |
| 4399 | ++__first; |
| 4400 | break; |
| 4401 | case 's': |
| 4402 | __ml = __start_matching_list(false); |
| 4403 | __ml->__add_class(ctype_base::space); |
| 4404 | ++__first; |
| 4405 | break; |
| 4406 | case 'S': |
| 4407 | __ml = __start_matching_list(true); |
| 4408 | __ml->__add_class(ctype_base::space); |
| 4409 | ++__first; |
| 4410 | break; |
| 4411 | case 'w': |
| 4412 | __ml = __start_matching_list(false); |
| 4413 | __ml->__add_class(ctype_base::alnum); |
| 4414 | __ml->__add_char('_'); |
| 4415 | ++__first; |
| 4416 | break; |
| 4417 | case 'W': |
| 4418 | __ml = __start_matching_list(true); |
| 4419 | __ml->__add_class(ctype_base::alnum); |
| 4420 | __ml->__add_char('_'); |
| 4421 | ++__first; |
| 4422 | break; |
| 4423 | } |
| 4424 | } |
| 4425 | return __first; |
| 4426 | } |
| 4427 | |
| 4428 | template <class _CharT, class _Traits> |
| 4429 | template <class _ForwardIterator> |
| 4430 | _ForwardIterator |
| 4431 | basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first, |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4432 | _ForwardIterator __last, |
| 4433 | basic_string<_CharT>* __str) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4434 | { |
| 4435 | if (__first != __last) |
| 4436 | { |
| 4437 | _ForwardIterator __t; |
| 4438 | unsigned __sum = 0; |
| 4439 | int __hd; |
| 4440 | switch (*__first) |
| 4441 | { |
| 4442 | case 'f': |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4443 | if (__str) |
| 4444 | *__str = _CharT(0xC); |
| 4445 | else |
| 4446 | __push_char(_CharT(0xC)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4447 | ++__first; |
| 4448 | break; |
| 4449 | case 'n': |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4450 | if (__str) |
| 4451 | *__str = _CharT(0xA); |
| 4452 | else |
| 4453 | __push_char(_CharT(0xA)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4454 | ++__first; |
| 4455 | break; |
| 4456 | case 'r': |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4457 | if (__str) |
| 4458 | *__str = _CharT(0xD); |
| 4459 | else |
| 4460 | __push_char(_CharT(0xD)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4461 | ++__first; |
| 4462 | break; |
| 4463 | case 't': |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4464 | if (__str) |
| 4465 | *__str = _CharT(0x9); |
| 4466 | else |
| 4467 | __push_char(_CharT(0x9)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4468 | ++__first; |
| 4469 | break; |
| 4470 | case 'v': |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4471 | if (__str) |
| 4472 | *__str = _CharT(0xB); |
| 4473 | else |
| 4474 | __push_char(_CharT(0xB)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4475 | ++__first; |
| 4476 | break; |
| 4477 | case 'c': |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4478 | if ((__t = _VSTD::next(__first)) != __last) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4479 | { |
Howard Hinnant | 1e1d051 | 2013-07-15 18:21:11 +0000 | [diff] [blame] | 4480 | if (('A' <= *__t && *__t <= 'Z') || |
| 4481 | ('a' <= *__t && *__t <= 'z')) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4482 | { |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4483 | if (__str) |
| 4484 | *__str = _CharT(*__t % 32); |
| 4485 | else |
| 4486 | __push_char(_CharT(*__t % 32)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4487 | __first = ++__t; |
| 4488 | } |
Howard Hinnant | 1e1d051 | 2013-07-15 18:21:11 +0000 | [diff] [blame] | 4489 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4490 | else |
| 4491 | throw regex_error(regex_constants::error_escape); |
| 4492 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4493 | } |
Howard Hinnant | 1e1d051 | 2013-07-15 18:21:11 +0000 | [diff] [blame] | 4494 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4495 | else |
| 4496 | throw regex_error(regex_constants::error_escape); |
| 4497 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4498 | break; |
| 4499 | case 'u': |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4500 | ++__first; |
| 4501 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4502 | if (__first == __last) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4503 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4504 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4505 | __hd = __traits_.value(*__first, 16); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4506 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4507 | if (__hd == -1) |
| 4508 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4509 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4510 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4511 | ++__first; |
| 4512 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4513 | if (__first == __last) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4514 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4515 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4516 | __hd = __traits_.value(*__first, 16); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4517 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4518 | if (__hd == -1) |
| 4519 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4520 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4521 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4522 | // drop through |
| 4523 | case 'x': |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4524 | ++__first; |
| 4525 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4526 | if (__first == __last) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4527 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4528 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4529 | __hd = __traits_.value(*__first, 16); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4530 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4531 | if (__hd == -1) |
| 4532 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4533 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4534 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4535 | ++__first; |
| 4536 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4537 | if (__first == __last) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4538 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4539 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4540 | __hd = __traits_.value(*__first, 16); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4541 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4542 | if (__hd == -1) |
| 4543 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4544 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4545 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4546 | if (__str) |
| 4547 | *__str = _CharT(__sum); |
| 4548 | else |
| 4549 | __push_char(_CharT(__sum)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4550 | ++__first; |
| 4551 | break; |
Marshall Clow | 21622af | 2014-05-21 16:29:50 +0000 | [diff] [blame] | 4552 | case '0': |
| 4553 | if (__str) |
| 4554 | *__str = _CharT(0); |
| 4555 | else |
| 4556 | __push_char(_CharT(0)); |
| 4557 | ++__first; |
| 4558 | break; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4559 | default: |
| 4560 | if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum)) |
| 4561 | { |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4562 | if (__str) |
| 4563 | *__str = *__first; |
| 4564 | else |
| 4565 | __push_char(*__first); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4566 | ++__first; |
| 4567 | } |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4568 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 918f2a8 | 2013-06-28 18:57:30 +0000 | [diff] [blame] | 4569 | else |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4570 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4571 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4572 | break; |
| 4573 | } |
| 4574 | } |
| 4575 | return __first; |
| 4576 | } |
| 4577 | |
| 4578 | template <class _CharT, class _Traits> |
| 4579 | template <class _ForwardIterator> |
| 4580 | _ForwardIterator |
| 4581 | basic_regex<_CharT, _Traits>::__parse_pattern_character(_ForwardIterator __first, |
| 4582 | _ForwardIterator __last) |
| 4583 | { |
| 4584 | if (__first != __last) |
| 4585 | { |
| 4586 | switch (*__first) |
| 4587 | { |
| 4588 | case '^': |
| 4589 | case '$': |
| 4590 | case '\\': |
| 4591 | case '.': |
| 4592 | case '*': |
| 4593 | case '+': |
| 4594 | case '?': |
| 4595 | case '(': |
| 4596 | case ')': |
| 4597 | case '[': |
| 4598 | case ']': |
| 4599 | case '{': |
| 4600 | case '}': |
| 4601 | case '|': |
| 4602 | break; |
| 4603 | default: |
| 4604 | __push_char(*__first); |
| 4605 | ++__first; |
| 4606 | break; |
| 4607 | } |
| 4608 | } |
| 4609 | return __first; |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4610 | } |
| 4611 | |
| 4612 | template <class _CharT, class _Traits> |
Howard Hinnant | 856846b | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4613 | template <class _ForwardIterator> |
| 4614 | _ForwardIterator |
| 4615 | basic_regex<_CharT, _Traits>::__parse_grep(_ForwardIterator __first, |
| 4616 | _ForwardIterator __last) |
| 4617 | { |
| 4618 | __owns_one_state<_CharT>* __sa = __end_; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4619 | _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | 856846b | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4620 | if (__t1 != __first) |
| 4621 | __parse_basic_reg_exp(__first, __t1); |
| 4622 | else |
| 4623 | __push_empty(); |
| 4624 | __first = __t1; |
| 4625 | if (__first != __last) |
| 4626 | ++__first; |
| 4627 | while (__first != __last) |
| 4628 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4629 | __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | 856846b | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4630 | __owns_one_state<_CharT>* __sb = __end_; |
| 4631 | if (__t1 != __first) |
| 4632 | __parse_basic_reg_exp(__first, __t1); |
| 4633 | else |
| 4634 | __push_empty(); |
| 4635 | __push_alternation(__sa, __sb); |
| 4636 | __first = __t1; |
| 4637 | if (__first != __last) |
| 4638 | ++__first; |
| 4639 | } |
| 4640 | return __first; |
| 4641 | } |
| 4642 | |
| 4643 | template <class _CharT, class _Traits> |
| 4644 | template <class _ForwardIterator> |
| 4645 | _ForwardIterator |
| 4646 | basic_regex<_CharT, _Traits>::__parse_egrep(_ForwardIterator __first, |
| 4647 | _ForwardIterator __last) |
| 4648 | { |
| 4649 | __owns_one_state<_CharT>* __sa = __end_; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4650 | _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | 856846b | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4651 | if (__t1 != __first) |
| 4652 | __parse_extended_reg_exp(__first, __t1); |
| 4653 | else |
| 4654 | __push_empty(); |
| 4655 | __first = __t1; |
| 4656 | if (__first != __last) |
| 4657 | ++__first; |
| 4658 | while (__first != __last) |
| 4659 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4660 | __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | 856846b | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4661 | __owns_one_state<_CharT>* __sb = __end_; |
| 4662 | if (__t1 != __first) |
| 4663 | __parse_extended_reg_exp(__first, __t1); |
| 4664 | else |
| 4665 | __push_empty(); |
| 4666 | __push_alternation(__sa, __sb); |
| 4667 | __first = __t1; |
| 4668 | if (__first != __last) |
| 4669 | ++__first; |
| 4670 | } |
| 4671 | return __first; |
| 4672 | } |
| 4673 | |
| 4674 | template <class _CharT, class _Traits> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4675 | void |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4676 | basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max, |
| 4677 | __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end, |
| 4678 | bool __greedy) |
| 4679 | { |
| 4680 | unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first())); |
| 4681 | __end_->first() = nullptr; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4682 | unique_ptr<__loop<_CharT> > __e2(new __loop<_CharT>(__loop_count_, |
| 4683 | __s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy, |
| 4684 | __min, __max)); |
| 4685 | __s->first() = nullptr; |
| 4686 | __e1.release(); |
| 4687 | __end_->first() = new __repeat_one_loop<_CharT>(__e2.get()); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4688 | __end_ = __e2->second(); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4689 | __s->first() = __e2.release(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4690 | ++__loop_count_; |
| 4691 | } |
| 4692 | |
| 4693 | template <class _CharT, class _Traits> |
| 4694 | void |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4695 | basic_regex<_CharT, _Traits>::__push_char(value_type __c) |
| 4696 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4697 | if (flags() & icase) |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4698 | __end_->first() = new __match_char_icase<_CharT, _Traits> |
| 4699 | (__traits_, __c, __end_->first()); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4700 | else if (flags() & collate) |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4701 | __end_->first() = new __match_char_collate<_CharT, _Traits> |
| 4702 | (__traits_, __c, __end_->first()); |
| 4703 | else |
| 4704 | __end_->first() = new __match_char<_CharT>(__c, __end_->first()); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 4705 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4706 | } |
| 4707 | |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4708 | template <class _CharT, class _Traits> |
| 4709 | void |
| 4710 | basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression() |
| 4711 | { |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 4712 | if (!(__flags_ & nosubs)) |
| 4713 | { |
| 4714 | __end_->first() = |
| 4715 | new __begin_marked_subexpression<_CharT>(++__marked_count_, |
| 4716 | __end_->first()); |
| 4717 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4718 | } |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4719 | } |
| 4720 | |
| 4721 | template <class _CharT, class _Traits> |
| 4722 | void |
| 4723 | basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub) |
| 4724 | { |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 4725 | if (!(__flags_ & nosubs)) |
| 4726 | { |
| 4727 | __end_->first() = |
| 4728 | new __end_marked_subexpression<_CharT>(__sub, __end_->first()); |
| 4729 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4730 | } |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4731 | } |
| 4732 | |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4733 | template <class _CharT, class _Traits> |
| 4734 | void |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 4735 | basic_regex<_CharT, _Traits>::__push_l_anchor() |
| 4736 | { |
| 4737 | __end_->first() = new __l_anchor<_CharT>(__end_->first()); |
| 4738 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4739 | } |
| 4740 | |
| 4741 | template <class _CharT, class _Traits> |
| 4742 | void |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4743 | basic_regex<_CharT, _Traits>::__push_r_anchor() |
| 4744 | { |
| 4745 | __end_->first() = new __r_anchor<_CharT>(__end_->first()); |
| 4746 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4747 | } |
| 4748 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4749 | template <class _CharT, class _Traits> |
| 4750 | void |
| 4751 | basic_regex<_CharT, _Traits>::__push_match_any() |
| 4752 | { |
| 4753 | __end_->first() = new __match_any<_CharT>(__end_->first()); |
| 4754 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4755 | } |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4756 | |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4757 | template <class _CharT, class _Traits> |
| 4758 | void |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4759 | basic_regex<_CharT, _Traits>::__push_match_any_but_newline() |
| 4760 | { |
| 4761 | __end_->first() = new __match_any_but_newline<_CharT>(__end_->first()); |
| 4762 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4763 | } |
| 4764 | |
| 4765 | template <class _CharT, class _Traits> |
| 4766 | void |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4767 | basic_regex<_CharT, _Traits>::__push_empty() |
| 4768 | { |
| 4769 | __end_->first() = new __empty_state<_CharT>(__end_->first()); |
| 4770 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4771 | } |
| 4772 | |
| 4773 | template <class _CharT, class _Traits> |
| 4774 | void |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4775 | basic_regex<_CharT, _Traits>::__push_word_boundary(bool __invert) |
| 4776 | { |
| 4777 | __end_->first() = new __word_boundary<_CharT, _Traits>(__traits_, __invert, |
| 4778 | __end_->first()); |
| 4779 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4780 | } |
| 4781 | |
| 4782 | template <class _CharT, class _Traits> |
| 4783 | void |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4784 | basic_regex<_CharT, _Traits>::__push_back_ref(int __i) |
| 4785 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4786 | if (flags() & icase) |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4787 | __end_->first() = new __back_ref_icase<_CharT, _Traits> |
| 4788 | (__traits_, __i, __end_->first()); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4789 | else if (flags() & collate) |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4790 | __end_->first() = new __back_ref_collate<_CharT, _Traits> |
| 4791 | (__traits_, __i, __end_->first()); |
| 4792 | else |
| 4793 | __end_->first() = new __back_ref<_CharT>(__i, __end_->first()); |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4794 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4795 | } |
| 4796 | |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4797 | template <class _CharT, class _Traits> |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 4798 | void |
| 4799 | basic_regex<_CharT, _Traits>::__push_alternation(__owns_one_state<_CharT>* __sa, |
| 4800 | __owns_one_state<_CharT>* __ea) |
| 4801 | { |
| 4802 | __sa->first() = new __alternate<_CharT>( |
| 4803 | static_cast<__owns_one_state<_CharT>*>(__sa->first()), |
| 4804 | static_cast<__owns_one_state<_CharT>*>(__ea->first())); |
| 4805 | __ea->first() = nullptr; |
| 4806 | __ea->first() = new __empty_state<_CharT>(__end_->first()); |
| 4807 | __end_->first() = nullptr; |
| 4808 | __end_->first() = new __empty_non_own_state<_CharT>(__ea->first()); |
| 4809 | __end_ = static_cast<__owns_one_state<_CharT>*>(__ea->first()); |
| 4810 | } |
| 4811 | |
| 4812 | template <class _CharT, class _Traits> |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4813 | __bracket_expression<_CharT, _Traits>* |
| 4814 | basic_regex<_CharT, _Traits>::__start_matching_list(bool __negate) |
| 4815 | { |
| 4816 | __bracket_expression<_CharT, _Traits>* __r = |
| 4817 | new __bracket_expression<_CharT, _Traits>(__traits_, __end_->first(), |
| 4818 | __negate, __flags_ & icase, |
| 4819 | __flags_ & collate); |
| 4820 | __end_->first() = __r; |
| 4821 | __end_ = __r; |
| 4822 | return __r; |
| 4823 | } |
| 4824 | |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4825 | template <class _CharT, class _Traits> |
| 4826 | void |
| 4827 | basic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp, |
Howard Hinnant | cd59acc | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 4828 | bool __invert, |
| 4829 | unsigned __mexp) |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4830 | { |
| 4831 | __end_->first() = new __lookahead<_CharT, _Traits>(__exp, __invert, |
Howard Hinnant | cd59acc | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 4832 | __end_->first(), __mexp); |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4833 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4834 | } |
| 4835 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 4836 | typedef basic_regex<char> regex; |
| 4837 | typedef basic_regex<wchar_t> wregex; |
| 4838 | |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4839 | // sub_match |
| 4840 | |
| 4841 | template <class _BidirectionalIterator> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 4842 | class _LIBCPP_TYPE_VIS_ONLY sub_match |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4843 | : public pair<_BidirectionalIterator, _BidirectionalIterator> |
| 4844 | { |
| 4845 | public: |
| 4846 | typedef _BidirectionalIterator iterator; |
| 4847 | typedef typename iterator_traits<iterator>::value_type value_type; |
| 4848 | typedef typename iterator_traits<iterator>::difference_type difference_type; |
| 4849 | typedef basic_string<value_type> string_type; |
| 4850 | |
| 4851 | bool matched; |
| 4852 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4853 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 4854 | _LIBCPP_CONSTEXPR sub_match() : matched() {} |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 4855 | |
| 4856 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4857 | difference_type length() const |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4858 | {return matched ? _VSTD::distance(this->first, this->second) : 0;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4859 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4860 | string_type str() const |
| 4861 | {return matched ? string_type(this->first, this->second) : string_type();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4862 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4863 | operator string_type() const |
| 4864 | {return str();} |
| 4865 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4866 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4867 | int compare(const sub_match& __s) const |
| 4868 | {return str().compare(__s.str());} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4869 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4870 | int compare(const string_type& __s) const |
| 4871 | {return str().compare(__s);} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4872 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4873 | int compare(const value_type* __s) const |
| 4874 | {return str().compare(__s);} |
| 4875 | }; |
| 4876 | |
| 4877 | typedef sub_match<const char*> csub_match; |
| 4878 | typedef sub_match<const wchar_t*> wcsub_match; |
| 4879 | typedef sub_match<string::const_iterator> ssub_match; |
| 4880 | typedef sub_match<wstring::const_iterator> wssub_match; |
| 4881 | |
| 4882 | template <class _BiIter> |
| 4883 | inline _LIBCPP_INLINE_VISIBILITY |
| 4884 | bool |
| 4885 | operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4886 | { |
| 4887 | return __x.compare(__y) == 0; |
| 4888 | } |
| 4889 | |
| 4890 | template <class _BiIter> |
| 4891 | inline _LIBCPP_INLINE_VISIBILITY |
| 4892 | bool |
| 4893 | operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4894 | { |
| 4895 | return !(__x == __y); |
| 4896 | } |
| 4897 | |
| 4898 | template <class _BiIter> |
| 4899 | inline _LIBCPP_INLINE_VISIBILITY |
| 4900 | bool |
| 4901 | operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4902 | { |
| 4903 | return __x.compare(__y) < 0; |
| 4904 | } |
| 4905 | |
| 4906 | template <class _BiIter> |
| 4907 | inline _LIBCPP_INLINE_VISIBILITY |
| 4908 | bool |
| 4909 | operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4910 | { |
| 4911 | return !(__y < __x); |
| 4912 | } |
| 4913 | |
| 4914 | template <class _BiIter> |
| 4915 | inline _LIBCPP_INLINE_VISIBILITY |
| 4916 | bool |
| 4917 | operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4918 | { |
| 4919 | return !(__x < __y); |
| 4920 | } |
| 4921 | |
| 4922 | template <class _BiIter> |
| 4923 | inline _LIBCPP_INLINE_VISIBILITY |
| 4924 | bool |
| 4925 | operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4926 | { |
| 4927 | return __y < __x; |
| 4928 | } |
| 4929 | |
| 4930 | template <class _BiIter, class _ST, class _SA> |
| 4931 | inline _LIBCPP_INLINE_VISIBILITY |
| 4932 | bool |
| 4933 | operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4934 | const sub_match<_BiIter>& __y) |
| 4935 | { |
Dan Albert | 0608625 | 2015-01-06 15:06:45 -0800 | [diff] [blame] | 4936 | 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] | 4937 | } |
| 4938 | |
| 4939 | template <class _BiIter, class _ST, class _SA> |
| 4940 | inline _LIBCPP_INLINE_VISIBILITY |
| 4941 | bool |
| 4942 | operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4943 | const sub_match<_BiIter>& __y) |
| 4944 | { |
| 4945 | return !(__x == __y); |
| 4946 | } |
| 4947 | |
| 4948 | template <class _BiIter, class _ST, class _SA> |
| 4949 | inline _LIBCPP_INLINE_VISIBILITY |
| 4950 | bool |
| 4951 | operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4952 | const sub_match<_BiIter>& __y) |
| 4953 | { |
Dan Albert | 0608625 | 2015-01-06 15:06:45 -0800 | [diff] [blame] | 4954 | 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] | 4955 | } |
| 4956 | |
| 4957 | template <class _BiIter, class _ST, class _SA> |
| 4958 | inline _LIBCPP_INLINE_VISIBILITY |
| 4959 | bool |
| 4960 | operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4961 | const sub_match<_BiIter>& __y) |
| 4962 | { |
| 4963 | return __y < __x; |
| 4964 | } |
| 4965 | |
| 4966 | template <class _BiIter, class _ST, class _SA> |
| 4967 | inline _LIBCPP_INLINE_VISIBILITY |
| 4968 | bool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4969 | const sub_match<_BiIter>& __y) |
| 4970 | { |
| 4971 | return !(__x < __y); |
| 4972 | } |
| 4973 | |
| 4974 | template <class _BiIter, class _ST, class _SA> |
| 4975 | inline _LIBCPP_INLINE_VISIBILITY |
| 4976 | bool |
| 4977 | operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4978 | const sub_match<_BiIter>& __y) |
| 4979 | { |
| 4980 | return !(__y < __x); |
| 4981 | } |
| 4982 | |
| 4983 | template <class _BiIter, class _ST, class _SA> |
| 4984 | inline _LIBCPP_INLINE_VISIBILITY |
| 4985 | bool |
| 4986 | operator==(const sub_match<_BiIter>& __x, |
| 4987 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4988 | { |
Dan Albert | 0608625 | 2015-01-06 15:06:45 -0800 | [diff] [blame] | 4989 | 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] | 4990 | } |
| 4991 | |
| 4992 | template <class _BiIter, class _ST, class _SA> |
| 4993 | inline _LIBCPP_INLINE_VISIBILITY |
| 4994 | bool |
| 4995 | operator!=(const sub_match<_BiIter>& __x, |
| 4996 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4997 | { |
| 4998 | return !(__x == __y); |
| 4999 | } |
| 5000 | |
| 5001 | template <class _BiIter, class _ST, class _SA> |
| 5002 | inline _LIBCPP_INLINE_VISIBILITY |
| 5003 | bool |
| 5004 | operator<(const sub_match<_BiIter>& __x, |
| 5005 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5006 | { |
Dan Albert | 0608625 | 2015-01-06 15:06:45 -0800 | [diff] [blame] | 5007 | 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] | 5008 | } |
| 5009 | |
| 5010 | template <class _BiIter, class _ST, class _SA> |
| 5011 | inline _LIBCPP_INLINE_VISIBILITY |
| 5012 | bool operator>(const sub_match<_BiIter>& __x, |
| 5013 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5014 | { |
| 5015 | return __y < __x; |
| 5016 | } |
| 5017 | |
| 5018 | template <class _BiIter, class _ST, class _SA> |
| 5019 | inline _LIBCPP_INLINE_VISIBILITY |
| 5020 | bool |
| 5021 | operator>=(const sub_match<_BiIter>& __x, |
| 5022 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5023 | { |
| 5024 | return !(__x < __y); |
| 5025 | } |
| 5026 | |
| 5027 | template <class _BiIter, class _ST, class _SA> |
| 5028 | inline _LIBCPP_INLINE_VISIBILITY |
| 5029 | bool |
| 5030 | operator<=(const sub_match<_BiIter>& __x, |
| 5031 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5032 | { |
| 5033 | return !(__y < __x); |
| 5034 | } |
| 5035 | |
| 5036 | template <class _BiIter> |
| 5037 | inline _LIBCPP_INLINE_VISIBILITY |
| 5038 | bool |
| 5039 | operator==(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5040 | const sub_match<_BiIter>& __y) |
| 5041 | { |
| 5042 | return __y.compare(__x) == 0; |
| 5043 | } |
| 5044 | |
| 5045 | template <class _BiIter> |
| 5046 | inline _LIBCPP_INLINE_VISIBILITY |
| 5047 | bool |
| 5048 | operator!=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5049 | const sub_match<_BiIter>& __y) |
| 5050 | { |
| 5051 | return !(__x == __y); |
| 5052 | } |
| 5053 | |
| 5054 | template <class _BiIter> |
| 5055 | inline _LIBCPP_INLINE_VISIBILITY |
| 5056 | bool |
| 5057 | operator<(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5058 | const sub_match<_BiIter>& __y) |
| 5059 | { |
| 5060 | return __y.compare(__x) > 0; |
| 5061 | } |
| 5062 | |
| 5063 | template <class _BiIter> |
| 5064 | inline _LIBCPP_INLINE_VISIBILITY |
| 5065 | bool |
| 5066 | operator>(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5067 | const sub_match<_BiIter>& __y) |
| 5068 | { |
| 5069 | return __y < __x; |
| 5070 | } |
| 5071 | |
| 5072 | template <class _BiIter> |
| 5073 | inline _LIBCPP_INLINE_VISIBILITY |
| 5074 | bool |
| 5075 | operator>=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5076 | const sub_match<_BiIter>& __y) |
| 5077 | { |
| 5078 | return !(__x < __y); |
| 5079 | } |
| 5080 | |
| 5081 | template <class _BiIter> |
| 5082 | inline _LIBCPP_INLINE_VISIBILITY |
| 5083 | bool |
| 5084 | operator<=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5085 | const sub_match<_BiIter>& __y) |
| 5086 | { |
| 5087 | return !(__y < __x); |
| 5088 | } |
| 5089 | |
| 5090 | template <class _BiIter> |
| 5091 | inline _LIBCPP_INLINE_VISIBILITY |
| 5092 | bool |
| 5093 | operator==(const sub_match<_BiIter>& __x, |
| 5094 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5095 | { |
| 5096 | return __x.compare(__y) == 0; |
| 5097 | } |
| 5098 | |
| 5099 | template <class _BiIter> |
| 5100 | inline _LIBCPP_INLINE_VISIBILITY |
| 5101 | bool |
| 5102 | operator!=(const sub_match<_BiIter>& __x, |
| 5103 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5104 | { |
| 5105 | return !(__x == __y); |
| 5106 | } |
| 5107 | |
| 5108 | template <class _BiIter> |
| 5109 | inline _LIBCPP_INLINE_VISIBILITY |
| 5110 | bool |
| 5111 | operator<(const sub_match<_BiIter>& __x, |
| 5112 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5113 | { |
| 5114 | return __x.compare(__y) < 0; |
| 5115 | } |
| 5116 | |
| 5117 | template <class _BiIter> |
| 5118 | inline _LIBCPP_INLINE_VISIBILITY |
| 5119 | bool |
| 5120 | operator>(const sub_match<_BiIter>& __x, |
| 5121 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5122 | { |
| 5123 | return __y < __x; |
| 5124 | } |
| 5125 | |
| 5126 | template <class _BiIter> |
| 5127 | inline _LIBCPP_INLINE_VISIBILITY |
| 5128 | bool |
| 5129 | operator>=(const sub_match<_BiIter>& __x, |
| 5130 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5131 | { |
| 5132 | return !(__x < __y); |
| 5133 | } |
| 5134 | |
| 5135 | template <class _BiIter> |
| 5136 | inline _LIBCPP_INLINE_VISIBILITY |
| 5137 | bool |
| 5138 | operator<=(const sub_match<_BiIter>& __x, |
| 5139 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5140 | { |
| 5141 | return !(__y < __x); |
| 5142 | } |
| 5143 | |
| 5144 | template <class _BiIter> |
| 5145 | inline _LIBCPP_INLINE_VISIBILITY |
| 5146 | bool |
| 5147 | operator==(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5148 | const sub_match<_BiIter>& __y) |
| 5149 | { |
| 5150 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5151 | return __y.compare(string_type(1, __x)) == 0; |
| 5152 | } |
| 5153 | |
| 5154 | template <class _BiIter> |
| 5155 | inline _LIBCPP_INLINE_VISIBILITY |
| 5156 | bool |
| 5157 | operator!=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5158 | const sub_match<_BiIter>& __y) |
| 5159 | { |
| 5160 | return !(__x == __y); |
| 5161 | } |
| 5162 | |
| 5163 | template <class _BiIter> |
| 5164 | inline _LIBCPP_INLINE_VISIBILITY |
| 5165 | bool |
| 5166 | operator<(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5167 | const sub_match<_BiIter>& __y) |
| 5168 | { |
| 5169 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5170 | return __y.compare(string_type(1, __x)) > 0; |
| 5171 | } |
| 5172 | |
| 5173 | template <class _BiIter> |
| 5174 | inline _LIBCPP_INLINE_VISIBILITY |
| 5175 | bool |
| 5176 | operator>(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5177 | const sub_match<_BiIter>& __y) |
| 5178 | { |
| 5179 | return __y < __x; |
| 5180 | } |
| 5181 | |
| 5182 | template <class _BiIter> |
| 5183 | inline _LIBCPP_INLINE_VISIBILITY |
| 5184 | bool |
| 5185 | operator>=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5186 | const sub_match<_BiIter>& __y) |
| 5187 | { |
| 5188 | return !(__x < __y); |
| 5189 | } |
| 5190 | |
| 5191 | template <class _BiIter> |
| 5192 | inline _LIBCPP_INLINE_VISIBILITY |
| 5193 | bool |
| 5194 | operator<=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5195 | const sub_match<_BiIter>& __y) |
| 5196 | { |
| 5197 | return !(__y < __x); |
| 5198 | } |
| 5199 | |
| 5200 | template <class _BiIter> |
| 5201 | inline _LIBCPP_INLINE_VISIBILITY |
| 5202 | bool |
| 5203 | operator==(const sub_match<_BiIter>& __x, |
| 5204 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5205 | { |
| 5206 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5207 | return __x.compare(string_type(1, __y)) == 0; |
| 5208 | } |
| 5209 | |
| 5210 | template <class _BiIter> |
| 5211 | inline _LIBCPP_INLINE_VISIBILITY |
| 5212 | bool |
| 5213 | operator!=(const sub_match<_BiIter>& __x, |
| 5214 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5215 | { |
| 5216 | return !(__x == __y); |
| 5217 | } |
| 5218 | |
| 5219 | template <class _BiIter> |
| 5220 | inline _LIBCPP_INLINE_VISIBILITY |
| 5221 | bool |
| 5222 | operator<(const sub_match<_BiIter>& __x, |
| 5223 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5224 | { |
| 5225 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5226 | return __x.compare(string_type(1, __y)) < 0; |
| 5227 | } |
| 5228 | |
| 5229 | template <class _BiIter> |
| 5230 | inline _LIBCPP_INLINE_VISIBILITY |
| 5231 | bool |
| 5232 | operator>(const sub_match<_BiIter>& __x, |
| 5233 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5234 | { |
| 5235 | return __y < __x; |
| 5236 | } |
| 5237 | |
| 5238 | template <class _BiIter> |
| 5239 | inline _LIBCPP_INLINE_VISIBILITY |
| 5240 | bool |
| 5241 | operator>=(const sub_match<_BiIter>& __x, |
| 5242 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5243 | { |
| 5244 | return !(__x < __y); |
| 5245 | } |
| 5246 | |
| 5247 | template <class _BiIter> |
| 5248 | inline _LIBCPP_INLINE_VISIBILITY |
| 5249 | bool |
| 5250 | operator<=(const sub_match<_BiIter>& __x, |
| 5251 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5252 | { |
| 5253 | return !(__y < __x); |
| 5254 | } |
| 5255 | |
| 5256 | template <class _CharT, class _ST, class _BiIter> |
| 5257 | inline _LIBCPP_INLINE_VISIBILITY |
| 5258 | basic_ostream<_CharT, _ST>& |
| 5259 | operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m) |
| 5260 | { |
| 5261 | return __os << __m.str(); |
| 5262 | } |
| 5263 | |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5264 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 5265 | class _LIBCPP_TYPE_VIS_ONLY match_results |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5266 | { |
| 5267 | public: |
| 5268 | typedef _Allocator allocator_type; |
| 5269 | typedef sub_match<_BidirectionalIterator> value_type; |
| 5270 | private: |
| 5271 | typedef vector<value_type, allocator_type> __container_type; |
| 5272 | |
| 5273 | __container_type __matches_; |
| 5274 | value_type __unmatched_; |
| 5275 | value_type __prefix_; |
| 5276 | value_type __suffix_; |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5277 | bool __ready_; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5278 | public: |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5279 | _BidirectionalIterator __position_start_; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5280 | typedef const value_type& const_reference; |
Marshall Clow | 103af34 | 2014-02-26 01:56:31 +0000 | [diff] [blame] | 5281 | typedef value_type& reference; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5282 | typedef typename __container_type::const_iterator const_iterator; |
| 5283 | typedef const_iterator iterator; |
| 5284 | typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; |
| 5285 | typedef typename allocator_traits<allocator_type>::size_type size_type; |
| 5286 | typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type; |
| 5287 | typedef basic_string<char_type> string_type; |
| 5288 | |
| 5289 | // construct/copy/destroy: |
| 5290 | explicit match_results(const allocator_type& __a = allocator_type()); |
| 5291 | // match_results(const match_results&) = default; |
| 5292 | // match_results& operator=(const match_results&) = default; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5293 | // match_results(match_results&& __m) = default; |
| 5294 | // match_results& operator=(match_results&& __m) = default; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5295 | // ~match_results() = default; |
| 5296 | |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5297 | _LIBCPP_INLINE_VISIBILITY |
| 5298 | bool ready() const {return __ready_;} |
| 5299 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5300 | // size: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5301 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5302 | size_type size() const {return __matches_.size();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5303 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5304 | size_type max_size() const {return __matches_.max_size();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5305 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5306 | bool empty() const {return size() == 0;} |
| 5307 | |
| 5308 | // element access: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5309 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5310 | difference_type length(size_type __sub = 0) const |
| 5311 | {return (*this)[__sub].length();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5312 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5313 | difference_type position(size_type __sub = 0) const |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5314 | {return _VSTD::distance(__position_start_, (*this)[__sub].first);} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5315 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5316 | string_type str(size_type __sub = 0) const |
| 5317 | {return (*this)[__sub].str();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5318 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5319 | const_reference operator[](size_type __n) const |
| 5320 | {return __n < __matches_.size() ? __matches_[__n] : __unmatched_;} |
| 5321 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5322 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5323 | const_reference prefix() const {return __prefix_;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5324 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5325 | const_reference suffix() const {return __suffix_;} |
| 5326 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5327 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c6fe8ca | 2011-10-08 14:36:16 +0000 | [diff] [blame] | 5328 | const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5329 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5330 | const_iterator end() const {return __matches_.end();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5331 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c6fe8ca | 2011-10-08 14:36:16 +0000 | [diff] [blame] | 5332 | const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5333 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5334 | const_iterator cend() const {return __matches_.end();} |
| 5335 | |
| 5336 | // format: |
| 5337 | template <class _OutputIter> |
| 5338 | _OutputIter |
| 5339 | format(_OutputIter __out, const char_type* __fmt_first, |
| 5340 | const char_type* __fmt_last, |
| 5341 | regex_constants::match_flag_type __flags = regex_constants::format_default) const; |
| 5342 | template <class _OutputIter, class _ST, class _SA> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5343 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5344 | _OutputIter |
| 5345 | format(_OutputIter __out, const basic_string<char_type, _ST, _SA>& __fmt, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5346 | regex_constants::match_flag_type __flags = regex_constants::format_default) const |
| 5347 | {return format(__out, __fmt.data(), __fmt.data() + __fmt.size(), __flags);} |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5348 | template <class _ST, class _SA> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5349 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5350 | basic_string<char_type, _ST, _SA> |
| 5351 | format(const basic_string<char_type, _ST, _SA>& __fmt, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5352 | regex_constants::match_flag_type __flags = regex_constants::format_default) const |
| 5353 | { |
| 5354 | basic_string<char_type, _ST, _SA> __r; |
| 5355 | format(back_inserter(__r), __fmt.data(), __fmt.data() + __fmt.size(), |
| 5356 | __flags); |
| 5357 | return __r; |
| 5358 | } |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5359 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5360 | string_type |
| 5361 | format(const char_type* __fmt, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5362 | regex_constants::match_flag_type __flags = regex_constants::format_default) const |
| 5363 | { |
| 5364 | string_type __r; |
| 5365 | format(back_inserter(__r), __fmt, |
| 5366 | __fmt + char_traits<char_type>::length(__fmt), __flags); |
| 5367 | return __r; |
| 5368 | } |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5369 | |
| 5370 | // allocator: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5371 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5372 | allocator_type get_allocator() const {return __matches_.get_allocator();} |
| 5373 | |
| 5374 | // swap: |
| 5375 | void swap(match_results& __m); |
| 5376 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5377 | template <class _Bp, class _Ap> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5378 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5379 | void __assign(_BidirectionalIterator __f, _BidirectionalIterator __l, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5380 | const match_results<_Bp, _Ap>& __m, bool __no_update_pos) |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5381 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5382 | _Bp __mf = __m.prefix().first; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5383 | __matches_.resize(__m.size()); |
| 5384 | for (size_type __i = 0; __i < __matches_.size(); ++__i) |
| 5385 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5386 | __matches_[__i].first = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].first)); |
| 5387 | __matches_[__i].second = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].second)); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5388 | __matches_[__i].matched = __m[__i].matched; |
| 5389 | } |
| 5390 | __unmatched_.first = __l; |
| 5391 | __unmatched_.second = __l; |
| 5392 | __unmatched_.matched = false; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5393 | __prefix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().first)); |
| 5394 | __prefix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().second)); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5395 | __prefix_.matched = __m.prefix().matched; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5396 | __suffix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().first)); |
| 5397 | __suffix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().second)); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5398 | __suffix_.matched = __m.suffix().matched; |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5399 | if (!__no_update_pos) |
| 5400 | __position_start_ = __prefix_.first; |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5401 | __ready_ = __m.ready(); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5402 | } |
| 5403 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5404 | private: |
| 5405 | void __init(unsigned __s, |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5406 | _BidirectionalIterator __f, _BidirectionalIterator __l, |
| 5407 | bool __no_update_pos = false); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5408 | |
| 5409 | template <class, class> friend class basic_regex; |
| 5410 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5411 | template <class _Bp, class _Ap, class _Cp, class _Tp> |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5412 | friend |
| 5413 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5414 | 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] | 5415 | regex_constants::match_flag_type); |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 5416 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5417 | template <class _Bp, class _Ap> |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5418 | friend |
| 5419 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5420 | operator==(const match_results<_Bp, _Ap>&, const match_results<_Bp, _Ap>&); |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5421 | |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 5422 | template <class, class> friend class __lookahead; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5423 | }; |
| 5424 | |
| 5425 | template <class _BidirectionalIterator, class _Allocator> |
| 5426 | match_results<_BidirectionalIterator, _Allocator>::match_results( |
| 5427 | const allocator_type& __a) |
| 5428 | : __matches_(__a), |
| 5429 | __unmatched_(), |
| 5430 | __prefix_(), |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5431 | __suffix_(), |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5432 | __position_start_(), |
| 5433 | __ready_(false) |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5434 | { |
| 5435 | } |
| 5436 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5437 | template <class _BidirectionalIterator, class _Allocator> |
| 5438 | void |
| 5439 | match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s, |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5440 | _BidirectionalIterator __f, _BidirectionalIterator __l, |
| 5441 | bool __no_update_pos) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5442 | { |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5443 | __unmatched_.first = __l; |
| 5444 | __unmatched_.second = __l; |
| 5445 | __unmatched_.matched = false; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5446 | __matches_.assign(__s, __unmatched_); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5447 | __prefix_.first = __f; |
| 5448 | __prefix_.second = __f; |
| 5449 | __prefix_.matched = false; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5450 | __suffix_ = __unmatched_; |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5451 | if (!__no_update_pos) |
| 5452 | __position_start_ = __prefix_.first; |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5453 | __ready_ = true; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5454 | } |
| 5455 | |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5456 | template <class _BidirectionalIterator, class _Allocator> |
| 5457 | template <class _OutputIter> |
| 5458 | _OutputIter |
| 5459 | match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __out, |
| 5460 | const char_type* __fmt_first, const char_type* __fmt_last, |
| 5461 | regex_constants::match_flag_type __flags) const |
| 5462 | { |
| 5463 | if (__flags & regex_constants::format_sed) |
| 5464 | { |
| 5465 | for (; __fmt_first != __fmt_last; ++__fmt_first) |
| 5466 | { |
| 5467 | if (*__fmt_first == '&') |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5468 | __out = _VSTD::copy(__matches_[0].first, __matches_[0].second, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5469 | __out); |
| 5470 | else if (*__fmt_first == '\\' && __fmt_first + 1 != __fmt_last) |
| 5471 | { |
| 5472 | ++__fmt_first; |
| 5473 | if ('0' <= *__fmt_first && *__fmt_first <= '9') |
| 5474 | { |
| 5475 | size_t __i = *__fmt_first - '0'; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5476 | __out = _VSTD::copy(__matches_[__i].first, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5477 | __matches_[__i].second, __out); |
| 5478 | } |
| 5479 | else |
| 5480 | { |
| 5481 | *__out = *__fmt_first; |
| 5482 | ++__out; |
| 5483 | } |
| 5484 | } |
| 5485 | else |
| 5486 | { |
| 5487 | *__out = *__fmt_first; |
| 5488 | ++__out; |
| 5489 | } |
| 5490 | } |
| 5491 | } |
| 5492 | else |
| 5493 | { |
| 5494 | for (; __fmt_first != __fmt_last; ++__fmt_first) |
| 5495 | { |
| 5496 | if (*__fmt_first == '$' && __fmt_first + 1 != __fmt_last) |
| 5497 | { |
| 5498 | switch (__fmt_first[1]) |
| 5499 | { |
| 5500 | case '$': |
| 5501 | *__out = *++__fmt_first; |
| 5502 | ++__out; |
| 5503 | break; |
| 5504 | case '&': |
| 5505 | ++__fmt_first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5506 | __out = _VSTD::copy(__matches_[0].first, __matches_[0].second, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5507 | __out); |
| 5508 | break; |
| 5509 | case '`': |
| 5510 | ++__fmt_first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5511 | __out = _VSTD::copy(__prefix_.first, __prefix_.second, __out); |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5512 | break; |
| 5513 | case '\'': |
| 5514 | ++__fmt_first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5515 | __out = _VSTD::copy(__suffix_.first, __suffix_.second, __out); |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5516 | break; |
| 5517 | default: |
| 5518 | if ('0' <= __fmt_first[1] && __fmt_first[1] <= '9') |
| 5519 | { |
| 5520 | ++__fmt_first; |
| 5521 | size_t __i = *__fmt_first - '0'; |
| 5522 | if (__fmt_first + 1 != __fmt_last && |
| 5523 | '0' <= __fmt_first[1] && __fmt_first[1] <= '9') |
| 5524 | { |
| 5525 | ++__fmt_first; |
| 5526 | __i = 10 * __i + *__fmt_first - '0'; |
| 5527 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5528 | __out = _VSTD::copy(__matches_[__i].first, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5529 | __matches_[__i].second, __out); |
| 5530 | } |
| 5531 | else |
| 5532 | { |
| 5533 | *__out = *__fmt_first; |
| 5534 | ++__out; |
| 5535 | } |
| 5536 | break; |
| 5537 | } |
| 5538 | } |
| 5539 | else |
| 5540 | { |
| 5541 | *__out = *__fmt_first; |
| 5542 | ++__out; |
| 5543 | } |
| 5544 | } |
| 5545 | } |
| 5546 | return __out; |
| 5547 | } |
| 5548 | |
| 5549 | template <class _BidirectionalIterator, class _Allocator> |
| 5550 | void |
| 5551 | match_results<_BidirectionalIterator, _Allocator>::swap(match_results& __m) |
| 5552 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5553 | using _VSTD::swap; |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5554 | swap(__matches_, __m.__matches_); |
| 5555 | swap(__unmatched_, __m.__unmatched_); |
| 5556 | swap(__prefix_, __m.__prefix_); |
| 5557 | swap(__suffix_, __m.__suffix_); |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5558 | swap(__position_start_, __m.__position_start_); |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5559 | swap(__ready_, __m.__ready_); |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5560 | } |
| 5561 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5562 | typedef match_results<const char*> cmatch; |
| 5563 | typedef match_results<const wchar_t*> wcmatch; |
| 5564 | typedef match_results<string::const_iterator> smatch; |
| 5565 | typedef match_results<wstring::const_iterator> wsmatch; |
| 5566 | |
| 5567 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5568 | bool |
| 5569 | operator==(const match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5570 | const match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5571 | { |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5572 | if (__x.__ready_ != __y.__ready_) |
| 5573 | return false; |
| 5574 | if (!__x.__ready_) |
| 5575 | return true; |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5576 | return __x.__matches_ == __y.__matches_ && |
| 5577 | __x.__prefix_ == __y.__prefix_ && |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5578 | __x.__suffix_ == __y.__suffix_; |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5579 | } |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5580 | |
| 5581 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5582 | inline _LIBCPP_INLINE_VISIBILITY |
| 5583 | bool |
| 5584 | operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5585 | const match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5586 | { |
| 5587 | return !(__x == __y); |
| 5588 | } |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5589 | |
| 5590 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5591 | inline _LIBCPP_INLINE_VISIBILITY |
| 5592 | void |
| 5593 | swap(match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5594 | match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5595 | { |
| 5596 | __x.swap(__y); |
| 5597 | } |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5598 | |
| 5599 | // regex_search |
| 5600 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5601 | template <class _CharT, class _Traits> |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5602 | template <class _Allocator> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5603 | bool |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5604 | basic_regex<_CharT, _Traits>::__match_at_start_ecma( |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5605 | const _CharT* __first, const _CharT* __last, |
| 5606 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5607 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5608 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5609 | vector<__state> __states; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5610 | __node* __st = __start_.get(); |
| 5611 | if (__st) |
| 5612 | { |
| 5613 | __states.push_back(__state()); |
| 5614 | __states.back().__do_ = 0; |
| 5615 | __states.back().__first_ = __first; |
| 5616 | __states.back().__current_ = __first; |
| 5617 | __states.back().__last_ = __last; |
| 5618 | __states.back().__sub_matches_.resize(mark_count()); |
| 5619 | __states.back().__loop_data_.resize(__loop_count()); |
| 5620 | __states.back().__node_ = __st; |
| 5621 | __states.back().__flags_ = __flags; |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5622 | __states.back().__at_first_ = __at_first; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5623 | do |
| 5624 | { |
| 5625 | __state& __s = __states.back(); |
| 5626 | if (__s.__node_) |
| 5627 | __s.__node_->__exec(__s); |
| 5628 | switch (__s.__do_) |
| 5629 | { |
| 5630 | case __state::__end_state: |
| 5631 | __m.__matches_[0].first = __first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5632 | __m.__matches_[0].second = _VSTD::next(__first, __s.__current_ - __first); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5633 | __m.__matches_[0].matched = true; |
| 5634 | for (unsigned __i = 0; __i < __s.__sub_matches_.size(); ++__i) |
| 5635 | __m.__matches_[__i+1] = __s.__sub_matches_[__i]; |
| 5636 | return true; |
| 5637 | case __state::__accept_and_consume: |
| 5638 | case __state::__repeat: |
| 5639 | case __state::__accept_but_not_consume: |
| 5640 | break; |
| 5641 | case __state::__split: |
| 5642 | { |
| 5643 | __state __snext = __s; |
| 5644 | __s.__node_->__exec_split(true, __s); |
| 5645 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5646 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5647 | } |
| 5648 | break; |
| 5649 | case __state::__reject: |
| 5650 | __states.pop_back(); |
| 5651 | break; |
| 5652 | default: |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 5653 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5654 | throw regex_error(regex_constants::__re_err_unknown); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 5655 | #endif |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5656 | break; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 5657 | |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5658 | } |
| 5659 | } while (!__states.empty()); |
| 5660 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5661 | return false; |
| 5662 | } |
| 5663 | |
| 5664 | template <class _CharT, class _Traits> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5665 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5666 | bool |
| 5667 | basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs( |
| 5668 | const _CharT* __first, const _CharT* __last, |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5669 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5670 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5671 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5672 | deque<__state> __states; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5673 | ptrdiff_t __highest_j = 0; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5674 | ptrdiff_t _Np = _VSTD::distance(__first, __last); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5675 | __node* __st = __start_.get(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5676 | if (__st) |
| 5677 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5678 | __states.push_back(__state()); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5679 | __states.back().__do_ = 0; |
| 5680 | __states.back().__first_ = __first; |
| 5681 | __states.back().__current_ = __first; |
| 5682 | __states.back().__last_ = __last; |
| 5683 | __states.back().__loop_data_.resize(__loop_count()); |
| 5684 | __states.back().__node_ = __st; |
| 5685 | __states.back().__flags_ = __flags; |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5686 | __states.back().__at_first_ = __at_first; |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5687 | bool __matched = false; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5688 | do |
| 5689 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5690 | __state& __s = __states.back(); |
| 5691 | if (__s.__node_) |
| 5692 | __s.__node_->__exec(__s); |
| 5693 | switch (__s.__do_) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5694 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5695 | case __state::__end_state: |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5696 | if (!__matched || __highest_j < __s.__current_ - __s.__first_) |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5697 | __highest_j = __s.__current_ - __s.__first_; |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5698 | __matched = true; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5699 | if (__highest_j == _Np) |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5700 | __states.clear(); |
| 5701 | else |
| 5702 | __states.pop_back(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5703 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5704 | case __state::__consume_input: |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5705 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5706 | case __state::__accept_and_consume: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5707 | __states.push_front(_VSTD::move(__s)); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5708 | __states.pop_back(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5709 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5710 | case __state::__repeat: |
| 5711 | case __state::__accept_but_not_consume: |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5712 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5713 | case __state::__split: |
| 5714 | { |
| 5715 | __state __snext = __s; |
| 5716 | __s.__node_->__exec_split(true, __s); |
| 5717 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5718 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5719 | } |
| 5720 | break; |
| 5721 | case __state::__reject: |
| 5722 | __states.pop_back(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5723 | break; |
| 5724 | default: |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 5725 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5726 | throw regex_error(regex_constants::__re_err_unknown); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 5727 | #endif |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5728 | break; |
| 5729 | } |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5730 | } while (!__states.empty()); |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5731 | if (__matched) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5732 | { |
| 5733 | __m.__matches_[0].first = __first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5734 | __m.__matches_[0].second = _VSTD::next(__first, __highest_j); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5735 | __m.__matches_[0].matched = true; |
| 5736 | return true; |
| 5737 | } |
| 5738 | } |
| 5739 | return false; |
| 5740 | } |
| 5741 | |
| 5742 | template <class _CharT, class _Traits> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5743 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5744 | bool |
| 5745 | basic_regex<_CharT, _Traits>::__match_at_start_posix_subs( |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5746 | const _CharT* __first, const _CharT* __last, |
| 5747 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5748 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5749 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5750 | vector<__state> __states; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5751 | __state __best_state; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5752 | ptrdiff_t __j = 0; |
| 5753 | ptrdiff_t __highest_j = 0; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5754 | ptrdiff_t _Np = _VSTD::distance(__first, __last); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5755 | __node* __st = __start_.get(); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5756 | if (__st) |
| 5757 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5758 | __states.push_back(__state()); |
| 5759 | __states.back().__do_ = 0; |
| 5760 | __states.back().__first_ = __first; |
| 5761 | __states.back().__current_ = __first; |
| 5762 | __states.back().__last_ = __last; |
| 5763 | __states.back().__sub_matches_.resize(mark_count()); |
| 5764 | __states.back().__loop_data_.resize(__loop_count()); |
| 5765 | __states.back().__node_ = __st; |
| 5766 | __states.back().__flags_ = __flags; |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5767 | __states.back().__at_first_ = __at_first; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5768 | const _CharT* __current = __first; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5769 | bool __matched = false; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5770 | do |
| 5771 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5772 | __state& __s = __states.back(); |
| 5773 | if (__s.__node_) |
| 5774 | __s.__node_->__exec(__s); |
| 5775 | switch (__s.__do_) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5776 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5777 | case __state::__end_state: |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5778 | if (!__matched || __highest_j < __s.__current_ - __s.__first_) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5779 | { |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5780 | __highest_j = __s.__current_ - __s.__first_; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5781 | __best_state = __s; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5782 | } |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5783 | __matched = true; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5784 | if (__highest_j == _Np) |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5785 | __states.clear(); |
| 5786 | else |
| 5787 | __states.pop_back(); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5788 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5789 | case __state::__accept_and_consume: |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 5790 | __j += __s.__current_ - __current; |
| 5791 | __current = __s.__current_; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5792 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5793 | case __state::__repeat: |
| 5794 | case __state::__accept_but_not_consume: |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5795 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5796 | case __state::__split: |
| 5797 | { |
| 5798 | __state __snext = __s; |
| 5799 | __s.__node_->__exec_split(true, __s); |
| 5800 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5801 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5802 | } |
| 5803 | break; |
| 5804 | case __state::__reject: |
| 5805 | __states.pop_back(); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5806 | break; |
| 5807 | default: |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 5808 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5809 | throw regex_error(regex_constants::__re_err_unknown); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 5810 | #endif |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5811 | break; |
| 5812 | } |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5813 | } while (!__states.empty()); |
| 5814 | if (__matched) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5815 | { |
| 5816 | __m.__matches_[0].first = __first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5817 | __m.__matches_[0].second = _VSTD::next(__first, __highest_j); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5818 | __m.__matches_[0].matched = true; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5819 | for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i) |
| 5820 | __m.__matches_[__i+1] = __best_state.__sub_matches_[__i]; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5821 | return true; |
| 5822 | } |
| 5823 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5824 | return false; |
| 5825 | } |
| 5826 | |
| 5827 | template <class _CharT, class _Traits> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5828 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5829 | bool |
| 5830 | basic_regex<_CharT, _Traits>::__match_at_start( |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5831 | const _CharT* __first, const _CharT* __last, |
| 5832 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5833 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5834 | { |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5835 | if ((__flags_ & 0x1F0) == ECMAScript) |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5836 | return __match_at_start_ecma(__first, __last, __m, __flags, __at_first); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5837 | if (mark_count() == 0) |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5838 | return __match_at_start_posix_nosubs(__first, __last, __m, __flags, __at_first); |
| 5839 | return __match_at_start_posix_subs(__first, __last, __m, __flags, __at_first); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5840 | } |
| 5841 | |
| 5842 | template <class _CharT, class _Traits> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5843 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5844 | bool |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5845 | basic_regex<_CharT, _Traits>::__search( |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5846 | const _CharT* __first, const _CharT* __last, |
| 5847 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5848 | regex_constants::match_flag_type __flags) const |
| 5849 | { |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5850 | __m.__init(1 + mark_count(), __first, __last, |
| 5851 | __flags & regex_constants::__no_update_pos); |
Howard Hinnant | 7670f7d | 2013-07-09 17:29:09 +0000 | [diff] [blame] | 5852 | if (__match_at_start(__first, __last, __m, __flags, |
| 5853 | !(__flags & regex_constants::__no_update_pos))) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5854 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5855 | __m.__prefix_.second = __m[0].first; |
| 5856 | __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; |
| 5857 | __m.__suffix_.first = __m[0].second; |
| 5858 | __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; |
| 5859 | return true; |
| 5860 | } |
Howard Hinnant | 8daa733 | 2010-07-29 01:15:27 +0000 | [diff] [blame] | 5861 | if (__first != __last && !(__flags & regex_constants::match_continuous)) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5862 | { |
Howard Hinnant | f3dcca0 | 2010-07-29 15:17:28 +0000 | [diff] [blame] | 5863 | __flags |= regex_constants::match_prev_avail; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5864 | for (++__first; __first != __last; ++__first) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5865 | { |
Howard Hinnant | f3dcca0 | 2010-07-29 15:17:28 +0000 | [diff] [blame] | 5866 | __m.__matches_.assign(__m.size(), __m.__unmatched_); |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5867 | if (__match_at_start(__first, __last, __m, __flags, false)) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5868 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5869 | __m.__prefix_.second = __m[0].first; |
| 5870 | __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; |
| 5871 | __m.__suffix_.first = __m[0].second; |
| 5872 | __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; |
| 5873 | return true; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5874 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5875 | __m.__matches_.assign(__m.size(), __m.__unmatched_); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5876 | } |
| 5877 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5878 | __m.__matches_.clear(); |
| 5879 | return false; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5880 | } |
| 5881 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5882 | template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5883 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5884 | bool |
| 5885 | regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 5886 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 5887 | const basic_regex<_CharT, _Traits>& __e, |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5888 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5889 | { |
Howard Hinnant | e840208 | 2013-07-11 15:32:55 +0000 | [diff] [blame] | 5890 | int __offset = (__flags & regex_constants::match_prev_avail) ? 1 : 0; |
| 5891 | basic_string<_CharT> __s(_VSTD::prev(__first, __offset), __last); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5892 | match_results<const _CharT*> __mc; |
Howard Hinnant | e840208 | 2013-07-11 15:32:55 +0000 | [diff] [blame] | 5893 | 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] | 5894 | __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5895 | return __r; |
| 5896 | } |
| 5897 | |
Howard Hinnant | a9602d5 | 2013-06-29 23:45:43 +0000 | [diff] [blame] | 5898 | template <class _Iter, class _Allocator, class _CharT, class _Traits> |
| 5899 | inline _LIBCPP_INLINE_VISIBILITY |
| 5900 | bool |
| 5901 | regex_search(__wrap_iter<_Iter> __first, |
| 5902 | __wrap_iter<_Iter> __last, |
| 5903 | match_results<__wrap_iter<_Iter>, _Allocator>& __m, |
| 5904 | const basic_regex<_CharT, _Traits>& __e, |
| 5905 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5906 | { |
| 5907 | match_results<const _CharT*> __mc; |
| 5908 | bool __r = __e.__search(__first.base(), __last.base(), __mc, __flags); |
| 5909 | __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos); |
| 5910 | return __r; |
| 5911 | } |
| 5912 | |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5913 | template <class _Allocator, class _CharT, class _Traits> |
| 5914 | inline _LIBCPP_INLINE_VISIBILITY |
| 5915 | bool |
| 5916 | regex_search(const _CharT* __first, const _CharT* __last, |
| 5917 | match_results<const _CharT*, _Allocator>& __m, |
| 5918 | const basic_regex<_CharT, _Traits>& __e, |
| 5919 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5920 | { |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5921 | return __e.__search(__first, __last, __m, __flags); |
| 5922 | } |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5923 | |
| 5924 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 5925 | inline _LIBCPP_INLINE_VISIBILITY |
| 5926 | bool |
| 5927 | regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 5928 | const basic_regex<_CharT, _Traits>& __e, |
| 5929 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5930 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5931 | basic_string<_CharT> __s(__first, __last); |
| 5932 | match_results<const _CharT*> __mc; |
| 5933 | return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
| 5934 | } |
| 5935 | |
| 5936 | template <class _CharT, class _Traits> |
| 5937 | inline _LIBCPP_INLINE_VISIBILITY |
| 5938 | bool |
| 5939 | regex_search(const _CharT* __first, const _CharT* __last, |
| 5940 | const basic_regex<_CharT, _Traits>& __e, |
| 5941 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5942 | { |
| 5943 | match_results<const _CharT*> __mc; |
| 5944 | return __e.__search(__first, __last, __mc, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5945 | } |
| 5946 | |
| 5947 | template <class _CharT, class _Allocator, class _Traits> |
| 5948 | inline _LIBCPP_INLINE_VISIBILITY |
| 5949 | bool |
| 5950 | regex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, |
| 5951 | const basic_regex<_CharT, _Traits>& __e, |
| 5952 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5953 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5954 | return __e.__search(__str, __str + _Traits::length(__str), __m, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5955 | } |
| 5956 | |
| 5957 | template <class _CharT, class _Traits> |
| 5958 | inline _LIBCPP_INLINE_VISIBILITY |
| 5959 | bool |
| 5960 | regex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, |
| 5961 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5962 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5963 | match_results<const _CharT*> __m; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5964 | return _VSTD::regex_search(__str, __m, __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5965 | } |
| 5966 | |
| 5967 | template <class _ST, class _SA, class _CharT, class _Traits> |
| 5968 | inline _LIBCPP_INLINE_VISIBILITY |
| 5969 | bool |
| 5970 | regex_search(const basic_string<_CharT, _ST, _SA>& __s, |
| 5971 | const basic_regex<_CharT, _Traits>& __e, |
| 5972 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5973 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5974 | match_results<const _CharT*> __mc; |
| 5975 | return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5976 | } |
| 5977 | |
| 5978 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 5979 | inline _LIBCPP_INLINE_VISIBILITY |
| 5980 | bool |
| 5981 | regex_search(const basic_string<_CharT, _ST, _SA>& __s, |
| 5982 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 5983 | const basic_regex<_CharT, _Traits>& __e, |
| 5984 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5985 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5986 | match_results<const _CharT*> __mc; |
| 5987 | bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5988 | __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] | 5989 | return __r; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5990 | } |
| 5991 | |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 5992 | #if _LIBCPP_STD_VER > 11 |
| 5993 | template <class _ST, class _SA, class _Ap, class _Cp, class _Tp> |
| 5994 | bool |
| 5995 | regex_search(const basic_string<_Cp, _ST, _SA>&& __s, |
| 5996 | match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&, |
| 5997 | const basic_regex<_Cp, _Tp>& __e, |
| 5998 | regex_constants::match_flag_type __flags = regex_constants::match_default) = delete; |
| 5999 | #endif |
| 6000 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6001 | // regex_match |
| 6002 | |
| 6003 | template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> |
| 6004 | bool |
| 6005 | regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6006 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 6007 | const basic_regex<_CharT, _Traits>& __e, |
| 6008 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6009 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6010 | bool __r = _VSTD::regex_search(__first, __last, __m, __e, |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6011 | __flags | regex_constants::match_continuous); |
| 6012 | if (__r) |
| 6013 | { |
| 6014 | __r = !__m.suffix().matched; |
| 6015 | if (!__r) |
| 6016 | __m.__matches_.clear(); |
| 6017 | } |
| 6018 | return __r; |
| 6019 | } |
| 6020 | |
| 6021 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6022 | inline _LIBCPP_INLINE_VISIBILITY |
| 6023 | bool |
| 6024 | regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6025 | const basic_regex<_CharT, _Traits>& __e, |
| 6026 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6027 | { |
| 6028 | match_results<_BidirectionalIterator> __m; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6029 | return _VSTD::regex_match(__first, __last, __m, __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6030 | } |
| 6031 | |
| 6032 | template <class _CharT, class _Allocator, class _Traits> |
| 6033 | inline _LIBCPP_INLINE_VISIBILITY |
| 6034 | bool |
| 6035 | regex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, |
| 6036 | const basic_regex<_CharT, _Traits>& __e, |
| 6037 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6038 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6039 | return _VSTD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6040 | } |
| 6041 | |
| 6042 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 6043 | inline _LIBCPP_INLINE_VISIBILITY |
| 6044 | bool |
| 6045 | regex_match(const basic_string<_CharT, _ST, _SA>& __s, |
| 6046 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 6047 | const basic_regex<_CharT, _Traits>& __e, |
| 6048 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6049 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6050 | return _VSTD::regex_match(__s.begin(), __s.end(), __m, __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6051 | } |
| 6052 | |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6053 | #if _LIBCPP_STD_VER > 11 |
| 6054 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 6055 | inline _LIBCPP_INLINE_VISIBILITY |
| 6056 | bool |
| 6057 | regex_match(const basic_string<_CharT, _ST, _SA>&& __s, |
| 6058 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 6059 | const basic_regex<_CharT, _Traits>& __e, |
| 6060 | regex_constants::match_flag_type __flags = regex_constants::match_default) = delete; |
| 6061 | #endif |
| 6062 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6063 | template <class _CharT, class _Traits> |
| 6064 | inline _LIBCPP_INLINE_VISIBILITY |
| 6065 | bool |
| 6066 | regex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, |
| 6067 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6068 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6069 | return _VSTD::regex_match(__str, __str + _Traits::length(__str), __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6070 | } |
| 6071 | |
| 6072 | template <class _ST, class _SA, class _CharT, class _Traits> |
| 6073 | inline _LIBCPP_INLINE_VISIBILITY |
| 6074 | bool |
| 6075 | regex_match(const basic_string<_CharT, _ST, _SA>& __s, |
| 6076 | const basic_regex<_CharT, _Traits>& __e, |
| 6077 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6078 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6079 | return _VSTD::regex_match(__s.begin(), __s.end(), __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6080 | } |
| 6081 | |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6082 | // regex_iterator |
| 6083 | |
| 6084 | template <class _BidirectionalIterator, |
| 6085 | class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type, |
| 6086 | class _Traits = regex_traits<_CharT> > |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 6087 | class _LIBCPP_TYPE_VIS_ONLY regex_iterator |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6088 | { |
| 6089 | public: |
| 6090 | typedef basic_regex<_CharT, _Traits> regex_type; |
| 6091 | typedef match_results<_BidirectionalIterator> value_type; |
| 6092 | typedef ptrdiff_t difference_type; |
| 6093 | typedef const value_type* pointer; |
| 6094 | typedef const value_type& reference; |
| 6095 | typedef forward_iterator_tag iterator_category; |
| 6096 | |
| 6097 | private: |
| 6098 | _BidirectionalIterator __begin_; |
| 6099 | _BidirectionalIterator __end_; |
| 6100 | const regex_type* __pregex_; |
| 6101 | regex_constants::match_flag_type __flags_; |
| 6102 | value_type __match_; |
| 6103 | |
| 6104 | public: |
| 6105 | regex_iterator(); |
| 6106 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6107 | const regex_type& __re, |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6108 | regex_constants::match_flag_type __m |
| 6109 | = regex_constants::match_default); |
| 6110 | #if _LIBCPP_STD_VER > 11 |
| 6111 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6112 | const regex_type&& __re, |
| 6113 | regex_constants::match_flag_type __m |
| 6114 | = regex_constants::match_default) = delete; |
| 6115 | #endif |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6116 | |
| 6117 | bool operator==(const regex_iterator& __x) const; |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6118 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6119 | bool operator!=(const regex_iterator& __x) const {return !(*this == __x);} |
| 6120 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6121 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6122 | reference operator*() const {return __match_;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6123 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6124 | pointer operator->() const {return &__match_;} |
| 6125 | |
| 6126 | regex_iterator& operator++(); |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6127 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6128 | regex_iterator operator++(int) |
| 6129 | { |
| 6130 | regex_iterator __t(*this); |
| 6131 | ++(*this); |
| 6132 | return __t; |
| 6133 | } |
| 6134 | }; |
| 6135 | |
| 6136 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6137 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_iterator() |
| 6138 | : __begin_(), __end_(), __pregex_(nullptr), __flags_(), __match_() |
| 6139 | { |
| 6140 | } |
| 6141 | |
| 6142 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6143 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6144 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6145 | const regex_type& __re, regex_constants::match_flag_type __m) |
| 6146 | : __begin_(__a), |
| 6147 | __end_(__b), |
| 6148 | __pregex_(&__re), |
| 6149 | __flags_(__m) |
| 6150 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6151 | _VSTD::regex_search(__begin_, __end_, __match_, *__pregex_, __flags_); |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6152 | } |
| 6153 | |
| 6154 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6155 | bool |
| 6156 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6157 | operator==(const regex_iterator& __x) const |
| 6158 | { |
| 6159 | if (__match_.empty() && __x.__match_.empty()) |
| 6160 | return true; |
| 6161 | if (__match_.empty() || __x.__match_.empty()) |
| 6162 | return false; |
| 6163 | return __begin_ == __x.__begin_ && |
| 6164 | __end_ == __x.__end_ && |
| 6165 | __pregex_ == __x.__pregex_ && |
| 6166 | __flags_ == __x.__flags_ && |
| 6167 | __match_[0] == __x.__match_[0]; |
| 6168 | } |
| 6169 | |
| 6170 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6171 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6172 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() |
| 6173 | { |
| 6174 | __flags_ |= regex_constants::__no_update_pos; |
| 6175 | _BidirectionalIterator __start = __match_[0].second; |
Howard Hinnant | a9602d5 | 2013-06-29 23:45:43 +0000 | [diff] [blame] | 6176 | if (__match_.empty()) |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6177 | { |
| 6178 | if (__start == __end_) |
| 6179 | { |
| 6180 | __match_ = value_type(); |
| 6181 | return *this; |
| 6182 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6183 | else if (_VSTD::regex_search(__start, __end_, __match_, *__pregex_, |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6184 | __flags_ | regex_constants::match_not_null | |
| 6185 | regex_constants::match_continuous)) |
| 6186 | return *this; |
| 6187 | else |
| 6188 | ++__start; |
| 6189 | } |
| 6190 | __flags_ |= regex_constants::match_prev_avail; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6191 | if (!_VSTD::regex_search(__start, __end_, __match_, *__pregex_, __flags_)) |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6192 | __match_ = value_type(); |
| 6193 | return *this; |
| 6194 | } |
| 6195 | |
| 6196 | typedef regex_iterator<const char*> cregex_iterator; |
| 6197 | typedef regex_iterator<const wchar_t*> wcregex_iterator; |
| 6198 | typedef regex_iterator<string::const_iterator> sregex_iterator; |
| 6199 | typedef regex_iterator<wstring::const_iterator> wsregex_iterator; |
| 6200 | |
| 6201 | // regex_token_iterator |
| 6202 | |
| 6203 | template <class _BidirectionalIterator, |
| 6204 | class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type, |
| 6205 | class _Traits = regex_traits<_CharT> > |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 6206 | class _LIBCPP_TYPE_VIS_ONLY regex_token_iterator |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6207 | { |
| 6208 | public: |
| 6209 | typedef basic_regex<_CharT, _Traits> regex_type; |
| 6210 | typedef sub_match<_BidirectionalIterator> value_type; |
| 6211 | typedef ptrdiff_t difference_type; |
| 6212 | typedef const value_type* pointer; |
| 6213 | typedef const value_type& reference; |
| 6214 | typedef forward_iterator_tag iterator_category; |
| 6215 | |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6216 | private: |
| 6217 | typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position; |
| 6218 | |
| 6219 | _Position __position_; |
| 6220 | const value_type* __result_; |
| 6221 | value_type __suffix_; |
| 6222 | ptrdiff_t _N_; |
| 6223 | vector<int> __subs_; |
| 6224 | |
| 6225 | public: |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6226 | regex_token_iterator(); |
| 6227 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6228 | const regex_type& __re, int __submatch = 0, |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6229 | regex_constants::match_flag_type __m = |
| 6230 | regex_constants::match_default); |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6231 | #if _LIBCPP_STD_VER > 11 |
| 6232 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6233 | const regex_type&& __re, int __submatch = 0, |
| 6234 | regex_constants::match_flag_type __m = |
| 6235 | regex_constants::match_default) = delete; |
| 6236 | #endif |
| 6237 | |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6238 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6239 | const regex_type& __re, const vector<int>& __submatches, |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6240 | regex_constants::match_flag_type __m = |
| 6241 | regex_constants::match_default); |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6242 | #if _LIBCPP_STD_VER > 11 |
| 6243 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6244 | const regex_type&& __re, const vector<int>& __submatches, |
| 6245 | regex_constants::match_flag_type __m = |
| 6246 | regex_constants::match_default) = delete; |
| 6247 | #endif |
| 6248 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6249 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6250 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6251 | const regex_type& __re, |
| 6252 | initializer_list<int> __submatches, |
| 6253 | regex_constants::match_flag_type __m = |
| 6254 | regex_constants::match_default); |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6255 | |
| 6256 | #if _LIBCPP_STD_VER > 11 |
| 6257 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6258 | const regex_type&& __re, |
| 6259 | initializer_list<int> __submatches, |
| 6260 | regex_constants::match_flag_type __m = |
| 6261 | regex_constants::match_default) = delete; |
| 6262 | #endif |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6263 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6264 | template <size_t _Np> |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6265 | regex_token_iterator(_BidirectionalIterator __a, |
| 6266 | _BidirectionalIterator __b, |
| 6267 | const regex_type& __re, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6268 | const int (&__submatches)[_Np], |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6269 | regex_constants::match_flag_type __m = |
| 6270 | regex_constants::match_default); |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6271 | #if _LIBCPP_STD_VER > 11 |
| 6272 | template <std::size_t _Np> |
| 6273 | regex_token_iterator(_BidirectionalIterator __a, |
| 6274 | _BidirectionalIterator __b, |
| 6275 | const regex_type&& __re, |
| 6276 | const int (&__submatches)[_Np], |
| 6277 | regex_constants::match_flag_type __m = |
| 6278 | regex_constants::match_default) = delete; |
| 6279 | #endif |
| 6280 | |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6281 | regex_token_iterator(const regex_token_iterator&); |
| 6282 | regex_token_iterator& operator=(const regex_token_iterator&); |
| 6283 | |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6284 | bool operator==(const regex_token_iterator& __x) const; |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6285 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6286 | bool operator!=(const regex_token_iterator& __x) const {return !(*this == __x);} |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6287 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6288 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6289 | const value_type& operator*() const {return *__result_;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6290 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6291 | const value_type* operator->() const {return __result_;} |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6292 | |
| 6293 | regex_token_iterator& operator++(); |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6294 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6295 | regex_token_iterator operator++(int) |
| 6296 | { |
| 6297 | regex_token_iterator __t(*this); |
| 6298 | ++(*this); |
| 6299 | return __t; |
| 6300 | } |
| 6301 | |
| 6302 | private: |
| 6303 | void __init(_BidirectionalIterator __a, _BidirectionalIterator __b); |
Marshall Clow | 0efd9dc | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6304 | void __establish_result () { |
| 6305 | if (__subs_[_N_] == -1) |
| 6306 | __result_ = &__position_->prefix(); |
| 6307 | else |
| 6308 | __result_ = &(*__position_)[__subs_[_N_]]; |
| 6309 | } |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6310 | }; |
| 6311 | |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6312 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6313 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6314 | regex_token_iterator() |
| 6315 | : __result_(nullptr), |
| 6316 | __suffix_(), |
| 6317 | _N_(0) |
| 6318 | { |
| 6319 | } |
| 6320 | |
| 6321 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6322 | void |
| 6323 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6324 | __init(_BidirectionalIterator __a, _BidirectionalIterator __b) |
| 6325 | { |
| 6326 | if (__position_ != _Position()) |
Marshall Clow | 0efd9dc | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6327 | __establish_result (); |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6328 | else if (__subs_[_N_] == -1) |
| 6329 | { |
| 6330 | __suffix_.matched = true; |
| 6331 | __suffix_.first = __a; |
| 6332 | __suffix_.second = __b; |
| 6333 | __result_ = &__suffix_; |
| 6334 | } |
| 6335 | else |
| 6336 | __result_ = nullptr; |
| 6337 | } |
| 6338 | |
| 6339 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6340 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6341 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6342 | const regex_type& __re, int __submatch, |
| 6343 | regex_constants::match_flag_type __m) |
| 6344 | : __position_(__a, __b, __re, __m), |
| 6345 | _N_(0), |
| 6346 | __subs_(1, __submatch) |
| 6347 | { |
| 6348 | __init(__a, __b); |
| 6349 | } |
| 6350 | |
| 6351 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6352 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6353 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6354 | const regex_type& __re, const vector<int>& __submatches, |
| 6355 | regex_constants::match_flag_type __m) |
| 6356 | : __position_(__a, __b, __re, __m), |
| 6357 | _N_(0), |
| 6358 | __subs_(__submatches) |
| 6359 | { |
| 6360 | __init(__a, __b); |
| 6361 | } |
| 6362 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6363 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 6364 | |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6365 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6366 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6367 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6368 | const regex_type& __re, |
| 6369 | initializer_list<int> __submatches, |
| 6370 | regex_constants::match_flag_type __m) |
| 6371 | : __position_(__a, __b, __re, __m), |
| 6372 | _N_(0), |
| 6373 | __subs_(__submatches) |
| 6374 | { |
| 6375 | __init(__a, __b); |
| 6376 | } |
| 6377 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6378 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 6379 | |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6380 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6381 | template <size_t _Np> |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6382 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6383 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6384 | const regex_type& __re, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6385 | const int (&__submatches)[_Np], |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6386 | regex_constants::match_flag_type __m) |
| 6387 | : __position_(__a, __b, __re, __m), |
| 6388 | _N_(0), |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6389 | __subs_(__submatches, __submatches + _Np) |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6390 | { |
| 6391 | __init(__a, __b); |
| 6392 | } |
| 6393 | |
| 6394 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6395 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6396 | regex_token_iterator(const regex_token_iterator& __x) |
| 6397 | : __position_(__x.__position_), |
| 6398 | __result_(__x.__result_), |
| 6399 | __suffix_(__x.__suffix_), |
| 6400 | _N_(__x._N_), |
| 6401 | __subs_(__x.__subs_) |
| 6402 | { |
| 6403 | if (__x.__result_ == &__x.__suffix_) |
Marshall Clow | 72fe0ae | 2014-01-13 17:47:08 +0000 | [diff] [blame] | 6404 | __result_ = &__suffix_; |
Marshall Clow | 0efd9dc | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6405 | else if ( __result_ != nullptr ) |
| 6406 | __establish_result (); |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6407 | } |
| 6408 | |
| 6409 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6410 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6411 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6412 | operator=(const regex_token_iterator& __x) |
| 6413 | { |
| 6414 | if (this != &__x) |
| 6415 | { |
| 6416 | __position_ = __x.__position_; |
| 6417 | if (__x.__result_ == &__x.__suffix_) |
Marshall Clow | 0efd9dc | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6418 | __result_ = &__suffix_; |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6419 | else |
| 6420 | __result_ = __x.__result_; |
| 6421 | __suffix_ = __x.__suffix_; |
| 6422 | _N_ = __x._N_; |
| 6423 | __subs_ = __x.__subs_; |
Marshall Clow | 0efd9dc | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6424 | |
| 6425 | if ( __result_ != nullptr && __result_ != &__suffix_ ) |
| 6426 | __establish_result(); |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6427 | } |
| 6428 | return *this; |
| 6429 | } |
| 6430 | |
| 6431 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6432 | bool |
| 6433 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6434 | operator==(const regex_token_iterator& __x) const |
| 6435 | { |
| 6436 | if (__result_ == nullptr && __x.__result_ == nullptr) |
| 6437 | return true; |
| 6438 | if (__result_ == &__suffix_ && __x.__result_ == &__x.__suffix_ && |
| 6439 | __suffix_ == __x.__suffix_) |
| 6440 | return true; |
| 6441 | if (__result_ == nullptr || __x.__result_ == nullptr) |
| 6442 | return false; |
| 6443 | if (__result_ == &__suffix_ || __x.__result_ == &__x.__suffix_) |
| 6444 | return false; |
| 6445 | return __position_ == __x.__position_ && _N_ == __x._N_ && |
| 6446 | __subs_ == __x.__subs_; |
| 6447 | } |
| 6448 | |
| 6449 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6450 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6451 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() |
| 6452 | { |
| 6453 | _Position __prev = __position_; |
| 6454 | if (__result_ == &__suffix_) |
| 6455 | __result_ = nullptr; |
| 6456 | else if (_N_ + 1 < __subs_.size()) |
| 6457 | { |
| 6458 | ++_N_; |
Marshall Clow | 0efd9dc | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6459 | __establish_result(); |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6460 | } |
| 6461 | else |
| 6462 | { |
| 6463 | _N_ = 0; |
| 6464 | ++__position_; |
| 6465 | if (__position_ != _Position()) |
Marshall Clow | 0efd9dc | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6466 | __establish_result(); |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6467 | else |
| 6468 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6469 | if (_VSTD::find(__subs_.begin(), __subs_.end(), -1) != __subs_.end() |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6470 | && __prev->suffix().length() != 0) |
| 6471 | { |
| 6472 | __suffix_.matched = true; |
| 6473 | __suffix_.first = __prev->suffix().first; |
| 6474 | __suffix_.second = __prev->suffix().second; |
| 6475 | __result_ = &__suffix_; |
| 6476 | } |
| 6477 | else |
| 6478 | __result_ = nullptr; |
| 6479 | } |
| 6480 | } |
| 6481 | return *this; |
| 6482 | } |
| 6483 | |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6484 | typedef regex_token_iterator<const char*> cregex_token_iterator; |
| 6485 | typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator; |
| 6486 | typedef regex_token_iterator<string::const_iterator> sregex_token_iterator; |
| 6487 | typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator; |
| 6488 | |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6489 | // regex_replace |
| 6490 | |
| 6491 | template <class _OutputIterator, class _BidirectionalIterator, |
| 6492 | class _Traits, class _CharT> |
| 6493 | _OutputIterator |
| 6494 | regex_replace(_OutputIterator __out, |
| 6495 | _BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6496 | const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt, |
| 6497 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6498 | { |
| 6499 | typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Iter; |
| 6500 | _Iter __i(__first, __last, __e, __flags); |
| 6501 | _Iter __eof; |
| 6502 | if (__i == __eof) |
| 6503 | { |
| 6504 | if (!(__flags & regex_constants::format_no_copy)) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6505 | __out = _VSTD::copy(__first, __last, __out); |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6506 | } |
| 6507 | else |
| 6508 | { |
| 6509 | sub_match<_BidirectionalIterator> __lm; |
| 6510 | for (size_t __len = char_traits<_CharT>::length(__fmt); __i != __eof; ++__i) |
| 6511 | { |
| 6512 | if (!(__flags & regex_constants::format_no_copy)) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6513 | __out = _VSTD::copy(__i->prefix().first, __i->prefix().second, __out); |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6514 | __out = __i->format(__out, __fmt, __fmt + __len, __flags); |
| 6515 | __lm = __i->suffix(); |
| 6516 | if (__flags & regex_constants::format_first_only) |
| 6517 | break; |
| 6518 | } |
| 6519 | if (!(__flags & regex_constants::format_no_copy)) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6520 | __out = _VSTD::copy(__lm.first, __lm.second, __out); |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6521 | } |
| 6522 | return __out; |
| 6523 | } |
| 6524 | |
| 6525 | template <class _OutputIterator, class _BidirectionalIterator, |
| 6526 | class _Traits, class _CharT, class _ST, class _SA> |
| 6527 | inline _LIBCPP_INLINE_VISIBILITY |
| 6528 | _OutputIterator |
| 6529 | regex_replace(_OutputIterator __out, |
| 6530 | _BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6531 | const basic_regex<_CharT, _Traits>& __e, |
| 6532 | const basic_string<_CharT, _ST, _SA>& __fmt, |
| 6533 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6534 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6535 | return _VSTD::regex_replace(__out, __first, __last, __e, __fmt.c_str(), __flags); |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6536 | } |
| 6537 | |
| 6538 | template <class _Traits, class _CharT, class _ST, class _SA, class _FST, |
| 6539 | class _FSA> |
| 6540 | inline _LIBCPP_INLINE_VISIBILITY |
| 6541 | basic_string<_CharT, _ST, _SA> |
| 6542 | regex_replace(const basic_string<_CharT, _ST, _SA>& __s, |
| 6543 | const basic_regex<_CharT, _Traits>& __e, |
| 6544 | const basic_string<_CharT, _FST, _FSA>& __fmt, |
| 6545 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6546 | { |
| 6547 | basic_string<_CharT, _ST, _SA> __r; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6548 | _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e, |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6549 | __fmt.c_str(), __flags); |
| 6550 | return __r; |
| 6551 | } |
| 6552 | |
| 6553 | template <class _Traits, class _CharT, class _ST, class _SA> |
| 6554 | inline _LIBCPP_INLINE_VISIBILITY |
| 6555 | basic_string<_CharT, _ST, _SA> |
| 6556 | regex_replace(const basic_string<_CharT, _ST, _SA>& __s, |
| 6557 | const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt, |
| 6558 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6559 | { |
| 6560 | basic_string<_CharT, _ST, _SA> __r; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6561 | _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e, |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6562 | __fmt, __flags); |
| 6563 | return __r; |
| 6564 | } |
| 6565 | |
| 6566 | template <class _Traits, class _CharT, class _ST, class _SA> |
| 6567 | inline _LIBCPP_INLINE_VISIBILITY |
| 6568 | basic_string<_CharT> |
| 6569 | regex_replace(const _CharT* __s, |
| 6570 | const basic_regex<_CharT, _Traits>& __e, |
| 6571 | const basic_string<_CharT, _ST, _SA>& __fmt, |
| 6572 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6573 | { |
| 6574 | basic_string<_CharT> __r; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6575 | _VSTD::regex_replace(back_inserter(__r), __s, |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6576 | __s + char_traits<_CharT>::length(__s), __e, |
| 6577 | __fmt.c_str(), __flags); |
| 6578 | return __r; |
| 6579 | } |
| 6580 | |
| 6581 | template <class _Traits, class _CharT> |
| 6582 | inline _LIBCPP_INLINE_VISIBILITY |
| 6583 | basic_string<_CharT> |
| 6584 | regex_replace(const _CharT* __s, |
| 6585 | const basic_regex<_CharT, _Traits>& __e, |
| 6586 | const _CharT* __fmt, |
| 6587 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6588 | { |
| 6589 | basic_string<_CharT> __r; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6590 | _VSTD::regex_replace(back_inserter(__r), __s, |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6591 | __s + char_traits<_CharT>::length(__s), __e, |
| 6592 | __fmt, __flags); |
| 6593 | return __r; |
| 6594 | } |
| 6595 | |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 6596 | _LIBCPP_END_NAMESPACE_STD |
| 6597 | |
| 6598 | #endif // _LIBCPP_REGEX |