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&); |
| 150 | basic_regex(basic_regex&&); |
| 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&); |
| 162 | basic_regex& operator=(basic_regex&&); |
| 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); |
| 170 | basic_regex& assign(basic_regex&& that); |
| 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; |
| 440 | typedef const_reference reference; |
| 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); |
| 452 | match_results(match_results&& m); |
| 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 | |
| 549 | template <class charT, class traits> |
| 550 | bool |
| 551 | regex_match(const charT* str, const basic_regex<charT, traits>& e, |
| 552 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 553 | |
| 554 | template <class ST, class SA, class charT, class traits> |
| 555 | bool |
| 556 | regex_match(const basic_string<charT, ST, SA>& s, |
| 557 | const basic_regex<charT, traits>& e, |
| 558 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 559 | |
| 560 | template <class BidirectionalIterator, class Allocator, class charT, class traits> |
| 561 | bool |
| 562 | regex_search(BidirectionalIterator first, BidirectionalIterator last, |
| 563 | match_results<BidirectionalIterator, Allocator>& m, |
| 564 | const basic_regex<charT, traits>& e, |
| 565 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 566 | |
| 567 | template <class BidirectionalIterator, class charT, class traits> |
| 568 | bool |
| 569 | regex_search(BidirectionalIterator first, BidirectionalIterator last, |
| 570 | const basic_regex<charT, traits>& e, |
| 571 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 572 | |
| 573 | template <class charT, class Allocator, class traits> |
| 574 | bool |
| 575 | regex_search(const charT* str, match_results<const charT*, Allocator>& m, |
| 576 | const basic_regex<charT, traits>& e, |
| 577 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 578 | |
| 579 | template <class charT, class traits> |
| 580 | bool |
| 581 | regex_search(const charT* str, const basic_regex<charT, traits>& e, |
| 582 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 583 | |
| 584 | template <class ST, class SA, class charT, class traits> |
| 585 | bool |
| 586 | regex_search(const basic_string<charT, ST, SA>& s, |
| 587 | const basic_regex<charT, traits>& e, |
| 588 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 589 | |
| 590 | template <class ST, class SA, class Allocator, class charT, class traits> |
| 591 | bool |
| 592 | regex_search(const basic_string<charT, ST, SA>& s, |
| 593 | match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m, |
| 594 | const basic_regex<charT, traits>& e, |
| 595 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 596 | |
| 597 | template <class OutputIterator, class BidirectionalIterator, |
| 598 | class traits, class charT, class ST, class SA> |
| 599 | OutputIterator |
| 600 | regex_replace(OutputIterator out, |
| 601 | BidirectionalIterator first, BidirectionalIterator last, |
| 602 | const basic_regex<charT, traits>& e, |
| 603 | const basic_string<charT, ST, SA>& fmt, |
| 604 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 605 | |
| 606 | template <class OutputIterator, class BidirectionalIterator, |
| 607 | class traits, class charT> |
| 608 | OutputIterator |
| 609 | regex_replace(OutputIterator out, |
| 610 | BidirectionalIterator first, BidirectionalIterator last, |
| 611 | const basic_regex<charT, traits>& e, const charT* fmt, |
| 612 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 613 | |
| 614 | template <class traits, class charT, class ST, class SA, class FST, class FSA>> |
| 615 | basic_string<charT, ST, SA> |
| 616 | regex_replace(const basic_string<charT, ST, SA>& s, |
| 617 | const basic_regex<charT, traits>& e, |
| 618 | const basic_string<charT, FST, FSA>& fmt, |
| 619 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 620 | |
| 621 | template <class traits, class charT, class ST, class SA> |
| 622 | basic_string<charT, ST, SA> |
| 623 | regex_replace(const basic_string<charT, ST, SA>& s, |
| 624 | const basic_regex<charT, traits>& e, const charT* fmt, |
| 625 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 626 | |
| 627 | template <class traits, class charT, class ST, class SA> |
| 628 | basic_string<charT> |
| 629 | regex_replace(const charT* s, |
| 630 | const basic_regex<charT, traits>& e, |
| 631 | const basic_string<charT, ST, SA>& fmt, |
| 632 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 633 | |
| 634 | template <class traits, class charT> |
| 635 | basic_string<charT> |
| 636 | regex_replace(const charT* s, |
| 637 | const basic_regex<charT, traits>& e, |
| 638 | const charT* fmt, |
| 639 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 640 | |
| 641 | template <class BidirectionalIterator, |
| 642 | class charT = typename iterator_traits< BidirectionalIterator>::value_type, |
| 643 | class traits = regex_traits<charT>> |
| 644 | class regex_iterator |
| 645 | { |
| 646 | public: |
| 647 | typedef basic_regex<charT, traits> regex_type; |
| 648 | typedef match_results<BidirectionalIterator> value_type; |
| 649 | typedef ptrdiff_t difference_type; |
| 650 | typedef const value_type* pointer; |
| 651 | typedef const value_type& reference; |
| 652 | typedef forward_iterator_tag iterator_category; |
| 653 | |
| 654 | regex_iterator(); |
| 655 | regex_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 656 | const regex_type& re, |
| 657 | regex_constants::match_flag_type m = regex_constants::match_default); |
| 658 | regex_iterator(const regex_iterator&); |
| 659 | regex_iterator& operator=(const regex_iterator&); |
| 660 | |
| 661 | bool operator==(const regex_iterator&) const; |
| 662 | bool operator!=(const regex_iterator&) const; |
| 663 | |
| 664 | const value_type& operator*() const; |
| 665 | const value_type* operator->() const; |
| 666 | |
| 667 | regex_iterator& operator++(); |
| 668 | regex_iterator operator++(int); |
| 669 | }; |
| 670 | |
| 671 | typedef regex_iterator<const char*> cregex_iterator; |
| 672 | typedef regex_iterator<const wchar_t*> wcregex_iterator; |
| 673 | typedef regex_iterator<string::const_iterator> sregex_iterator; |
| 674 | typedef regex_iterator<wstring::const_iterator> wsregex_iterator; |
| 675 | |
| 676 | template <class BidirectionalIterator, |
| 677 | class charT = typename iterator_traits< BidirectionalIterator>::value_type, |
| 678 | class traits = regex_traits<charT>> |
| 679 | class regex_token_iterator |
| 680 | { |
| 681 | public: |
| 682 | typedef basic_regex<charT, traits> regex_type; |
| 683 | typedef sub_match<BidirectionalIterator> value_type; |
| 684 | typedef ptrdiff_t difference_type; |
| 685 | typedef const value_type* pointer; |
| 686 | typedef const value_type& reference; |
| 687 | typedef forward_iterator_tag iterator_category; |
| 688 | |
| 689 | regex_token_iterator(); |
| 690 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 691 | const regex_type& re, int submatch = 0, |
| 692 | regex_constants::match_flag_type m = regex_constants::match_default); |
| 693 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 694 | const regex_type& re, const vector<int>& submatches, |
| 695 | regex_constants::match_flag_type m = regex_constants::match_default); |
| 696 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 697 | const regex_type& re, initializer_list<int> submatches, |
| 698 | regex_constants::match_flag_type m = regex_constants::match_default); |
| 699 | template <size_t N> |
| 700 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 701 | const regex_type& re, const int (&submatches)[N], |
| 702 | regex_constants::match_flag_type m = regex_constants::match_default); |
| 703 | regex_token_iterator(const regex_token_iterator&); |
| 704 | regex_token_iterator& operator=(const regex_token_iterator&); |
| 705 | |
| 706 | bool operator==(const regex_token_iterator&) const; |
| 707 | bool operator!=(const regex_token_iterator&) const; |
| 708 | |
| 709 | const value_type& operator*() const; |
| 710 | const value_type* operator->() const; |
| 711 | |
| 712 | regex_token_iterator& operator++(); |
| 713 | regex_token_iterator operator++(int); |
| 714 | }; |
| 715 | |
| 716 | typedef regex_token_iterator<const char*> cregex_token_iterator; |
| 717 | typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator; |
| 718 | typedef regex_token_iterator<string::const_iterator> sregex_token_iterator; |
| 719 | typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator; |
| 720 | |
| 721 | } // std |
| 722 | */ |
| 723 | |
| 724 | #include <__config> |
| 725 | #include <stdexcept> |
| 726 | #include <__locale> |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 727 | #include <initializer_list> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 728 | #include <utility> |
| 729 | #include <iterator> |
| 730 | #include <string> |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 731 | #include <memory> |
| 732 | #include <vector> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 733 | #include <deque> |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 734 | |
| 735 | #pragma GCC system_header |
| 736 | |
| 737 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 738 | |
| 739 | namespace regex_constants |
| 740 | { |
| 741 | |
| 742 | // syntax_option_type |
| 743 | |
| 744 | enum syntax_option_type |
| 745 | { |
| 746 | icase = 1 << 0, |
| 747 | nosubs = 1 << 1, |
| 748 | optimize = 1 << 2, |
| 749 | collate = 1 << 3, |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 750 | ECMAScript = 0, |
| 751 | basic = 1 << 4, |
| 752 | extended = 1 << 5, |
| 753 | awk = 1 << 6, |
| 754 | grep = 1 << 7, |
| 755 | egrep = 1 << 8 |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 756 | }; |
| 757 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 758 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 759 | /*constexpr*/ |
| 760 | syntax_option_type |
| 761 | operator~(syntax_option_type __x) |
| 762 | { |
| 763 | return syntax_option_type(~int(__x)); |
| 764 | } |
| 765 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 766 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 767 | /*constexpr*/ |
| 768 | syntax_option_type |
| 769 | operator&(syntax_option_type __x, syntax_option_type __y) |
| 770 | { |
| 771 | return syntax_option_type(int(__x) & int(__y)); |
| 772 | } |
| 773 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 774 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 775 | /*constexpr*/ |
| 776 | syntax_option_type |
| 777 | operator|(syntax_option_type __x, syntax_option_type __y) |
| 778 | { |
| 779 | return syntax_option_type(int(__x) | int(__y)); |
| 780 | } |
| 781 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 782 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 783 | /*constexpr*/ |
| 784 | syntax_option_type |
| 785 | operator^(syntax_option_type __x, syntax_option_type __y) |
| 786 | { |
| 787 | return syntax_option_type(int(__x) ^ int(__y)); |
| 788 | } |
| 789 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 790 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 791 | /*constexpr*/ |
| 792 | syntax_option_type& |
| 793 | operator&=(syntax_option_type& __x, syntax_option_type __y) |
| 794 | { |
| 795 | __x = __x & __y; |
| 796 | return __x; |
| 797 | } |
| 798 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 799 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 800 | /*constexpr*/ |
| 801 | syntax_option_type& |
| 802 | operator|=(syntax_option_type& __x, syntax_option_type __y) |
| 803 | { |
| 804 | __x = __x | __y; |
| 805 | return __x; |
| 806 | } |
| 807 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 808 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 809 | /*constexpr*/ |
| 810 | syntax_option_type& |
| 811 | operator^=(syntax_option_type& __x, syntax_option_type __y) |
| 812 | { |
| 813 | __x = __x ^ __y; |
| 814 | return __x; |
| 815 | } |
| 816 | |
| 817 | // match_flag_type |
| 818 | |
| 819 | enum match_flag_type |
| 820 | { |
| 821 | match_default = 0, |
| 822 | match_not_bol = 1 << 0, |
| 823 | match_not_eol = 1 << 1, |
| 824 | match_not_bow = 1 << 2, |
| 825 | match_not_eow = 1 << 3, |
| 826 | match_any = 1 << 4, |
| 827 | match_not_null = 1 << 5, |
| 828 | match_continuous = 1 << 6, |
| 829 | match_prev_avail = 1 << 7, |
| 830 | format_default = 0, |
| 831 | format_sed = 1 << 8, |
| 832 | format_no_copy = 1 << 9, |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 833 | format_first_only = 1 << 10, |
| 834 | __no_update_pos = 1 << 11 |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 835 | }; |
| 836 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 837 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 838 | /*constexpr*/ |
| 839 | match_flag_type |
| 840 | operator~(match_flag_type __x) |
| 841 | { |
| 842 | return match_flag_type(~int(__x)); |
| 843 | } |
| 844 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 845 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 846 | /*constexpr*/ |
| 847 | match_flag_type |
| 848 | operator&(match_flag_type __x, match_flag_type __y) |
| 849 | { |
| 850 | return match_flag_type(int(__x) & int(__y)); |
| 851 | } |
| 852 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 853 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 854 | /*constexpr*/ |
| 855 | match_flag_type |
| 856 | operator|(match_flag_type __x, match_flag_type __y) |
| 857 | { |
| 858 | return match_flag_type(int(__x) | int(__y)); |
| 859 | } |
| 860 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 861 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 862 | /*constexpr*/ |
| 863 | match_flag_type |
| 864 | operator^(match_flag_type __x, match_flag_type __y) |
| 865 | { |
| 866 | return match_flag_type(int(__x) ^ int(__y)); |
| 867 | } |
| 868 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 869 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 870 | /*constexpr*/ |
| 871 | match_flag_type& |
| 872 | operator&=(match_flag_type& __x, match_flag_type __y) |
| 873 | { |
| 874 | __x = __x & __y; |
| 875 | return __x; |
| 876 | } |
| 877 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 878 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 879 | /*constexpr*/ |
| 880 | match_flag_type& |
| 881 | operator|=(match_flag_type& __x, match_flag_type __y) |
| 882 | { |
| 883 | __x = __x | __y; |
| 884 | return __x; |
| 885 | } |
| 886 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 887 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 888 | /*constexpr*/ |
| 889 | match_flag_type& |
| 890 | operator^=(match_flag_type& __x, match_flag_type __y) |
| 891 | { |
| 892 | __x = __x ^ __y; |
| 893 | return __x; |
| 894 | } |
| 895 | |
| 896 | enum error_type |
| 897 | { |
| 898 | error_collate = 1, |
| 899 | error_ctype, |
| 900 | error_escape, |
| 901 | error_backref, |
| 902 | error_brack, |
| 903 | error_paren, |
| 904 | error_brace, |
| 905 | error_badbrace, |
| 906 | error_range, |
| 907 | error_space, |
| 908 | error_badrepeat, |
| 909 | error_complexity, |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 910 | error_stack, |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 911 | __re_err_grammar, |
| 912 | __re_err_empty, |
| 913 | __re_err_unknown |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 914 | }; |
| 915 | |
| 916 | } // regex_constants |
| 917 | |
| 918 | class _LIBCPP_EXCEPTION_ABI regex_error |
| 919 | : public runtime_error |
| 920 | { |
| 921 | regex_constants::error_type __code_; |
| 922 | public: |
| 923 | explicit regex_error(regex_constants::error_type __ecode); |
| 924 | virtual ~regex_error() throw(); |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 925 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 926 | regex_constants::error_type code() const {return __code_;} |
| 927 | }; |
| 928 | |
| 929 | template <class _CharT> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 930 | struct _LIBCPP_VISIBLE regex_traits |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 931 | { |
| 932 | public: |
| 933 | typedef _CharT char_type; |
| 934 | typedef basic_string<char_type> string_type; |
| 935 | typedef locale locale_type; |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 936 | typedef ctype_base::mask char_class_type; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 937 | |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 938 | static const char_class_type __regex_word = 0x80; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 939 | private: |
| 940 | locale __loc_; |
| 941 | const ctype<char_type>* __ct_; |
| 942 | const collate<char_type>* __col_; |
| 943 | |
| 944 | public: |
| 945 | regex_traits(); |
| 946 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 947 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 948 | static size_t length(const char_type* __p) |
| 949 | {return char_traits<char_type>::length(__p);} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 950 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 951 | char_type translate(char_type __c) const {return __c;} |
| 952 | char_type translate_nocase(char_type __c) const; |
| 953 | template <class _ForwardIterator> |
| 954 | string_type |
| 955 | transform(_ForwardIterator __f, _ForwardIterator __l) const; |
| 956 | template <class _ForwardIterator> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 957 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 958 | string_type |
| 959 | transform_primary( _ForwardIterator __f, _ForwardIterator __l) const |
| 960 | {return __transform_primary(__f, __l, char_type());} |
| 961 | template <class _ForwardIterator> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 962 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 963 | string_type |
| 964 | lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const |
| 965 | {return __lookup_collatename(__f, __l, char_type());} |
| 966 | template <class _ForwardIterator> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 967 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 968 | char_class_type |
| 969 | lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 970 | bool __icase = false) const |
| 971 | {return __lookup_classname(__f, __l, __icase, char_type());} |
| 972 | bool isctype(char_type __c, char_class_type __m) const; |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 973 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 974 | int value(char_type __ch, int __radix) const |
| 975 | {return __value(__ch, __radix);} |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 976 | locale_type imbue(locale_type __l); |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 977 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 978 | locale_type getloc()const {return __loc_;} |
| 979 | |
| 980 | private: |
| 981 | void __init(); |
| 982 | |
| 983 | template <class _ForwardIterator> |
| 984 | string_type |
| 985 | __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const; |
| 986 | template <class _ForwardIterator> |
| 987 | string_type |
| 988 | __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; |
| 989 | |
| 990 | template <class _ForwardIterator> |
| 991 | string_type |
| 992 | __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const; |
| 993 | template <class _ForwardIterator> |
| 994 | string_type |
| 995 | __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 996 | |
| 997 | template <class _ForwardIterator> |
| 998 | char_class_type |
| 999 | __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
| 1000 | bool __icase, char) const; |
| 1001 | template <class _ForwardIterator> |
| 1002 | char_class_type |
| 1003 | __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
| 1004 | bool __icase, wchar_t) const; |
| 1005 | |
| 1006 | static int __value(unsigned char __ch, int __radix); |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1007 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1008 | int __value(char __ch, int __radix) const |
| 1009 | {return __value(static_cast<unsigned char>(__ch), __radix);} |
| 1010 | int __value(wchar_t __ch, int __radix) const; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1011 | }; |
| 1012 | |
| 1013 | template <class _CharT> |
| 1014 | regex_traits<_CharT>::regex_traits() |
| 1015 | { |
| 1016 | __init(); |
| 1017 | } |
| 1018 | |
| 1019 | template <class _CharT> |
| 1020 | typename regex_traits<_CharT>::char_type |
| 1021 | regex_traits<_CharT>::translate_nocase(char_type __c) const |
| 1022 | { |
| 1023 | return __ct_->tolower(__c); |
| 1024 | } |
| 1025 | |
| 1026 | template <class _CharT> |
| 1027 | template <class _ForwardIterator> |
| 1028 | typename regex_traits<_CharT>::string_type |
| 1029 | regex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const |
| 1030 | { |
| 1031 | string_type __s(__f, __l); |
| 1032 | return __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1033 | } |
| 1034 | |
| 1035 | template <class _CharT> |
| 1036 | void |
| 1037 | regex_traits<_CharT>::__init() |
| 1038 | { |
| 1039 | __ct_ = &use_facet<ctype<char_type> >(__loc_); |
| 1040 | __col_ = &use_facet<collate<char_type> >(__loc_); |
| 1041 | } |
| 1042 | |
| 1043 | template <class _CharT> |
| 1044 | typename regex_traits<_CharT>::locale_type |
| 1045 | regex_traits<_CharT>::imbue(locale_type __l) |
| 1046 | { |
| 1047 | locale __r = __loc_; |
| 1048 | __loc_ = __l; |
| 1049 | __init(); |
| 1050 | return __r; |
| 1051 | } |
| 1052 | |
| 1053 | // transform_primary is very FreeBSD-specific |
| 1054 | |
| 1055 | template <class _CharT> |
| 1056 | template <class _ForwardIterator> |
| 1057 | typename regex_traits<_CharT>::string_type |
| 1058 | regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, |
| 1059 | _ForwardIterator __l, char) const |
| 1060 | { |
| 1061 | const string_type __s(__f, __l); |
| 1062 | string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1063 | switch (__d.size()) |
| 1064 | { |
| 1065 | case 1: |
| 1066 | break; |
| 1067 | case 12: |
| 1068 | __d[11] = __d[3]; |
| 1069 | break; |
| 1070 | default: |
| 1071 | __d.clear(); |
| 1072 | break; |
| 1073 | } |
| 1074 | return __d; |
| 1075 | } |
| 1076 | |
| 1077 | template <class _CharT> |
| 1078 | template <class _ForwardIterator> |
| 1079 | typename regex_traits<_CharT>::string_type |
| 1080 | regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, |
| 1081 | _ForwardIterator __l, wchar_t) const |
| 1082 | { |
| 1083 | const string_type __s(__f, __l); |
| 1084 | string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1085 | switch (__d.size()) |
| 1086 | { |
| 1087 | case 1: |
| 1088 | break; |
| 1089 | case 3: |
| 1090 | __d[2] = __d[0]; |
| 1091 | break; |
| 1092 | default: |
| 1093 | __d.clear(); |
| 1094 | break; |
| 1095 | } |
| 1096 | return __d; |
| 1097 | } |
| 1098 | |
| 1099 | // lookup_collatename is very FreeBSD-specific |
| 1100 | |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1101 | string __get_collation_name(const char* __s); |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1102 | |
| 1103 | template <class _CharT> |
| 1104 | template <class _ForwardIterator> |
| 1105 | typename regex_traits<_CharT>::string_type |
| 1106 | regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, |
| 1107 | _ForwardIterator __l, char) const |
| 1108 | { |
| 1109 | string_type __s(__f, __l); |
| 1110 | string_type __r; |
| 1111 | if (!__s.empty()) |
| 1112 | { |
| 1113 | __r = __get_collation_name(__s.c_str()); |
| 1114 | if (__r.empty() && __s.size() <= 2) |
| 1115 | { |
| 1116 | __r = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1117 | if (__r.size() == 1 || __r.size() == 12) |
| 1118 | __r = __s; |
| 1119 | else |
| 1120 | __r.clear(); |
| 1121 | } |
| 1122 | } |
| 1123 | return __r; |
| 1124 | } |
| 1125 | |
| 1126 | template <class _CharT> |
| 1127 | template <class _ForwardIterator> |
| 1128 | typename regex_traits<_CharT>::string_type |
| 1129 | regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, |
| 1130 | _ForwardIterator __l, wchar_t) const |
| 1131 | { |
| 1132 | string_type __s(__f, __l); |
| 1133 | string __n; |
| 1134 | __n.reserve(__s.size()); |
| 1135 | for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); |
| 1136 | __i != __e; ++__i) |
| 1137 | { |
| 1138 | if (static_cast<unsigned>(*__i) >= 127) |
| 1139 | return string_type(); |
| 1140 | __n.push_back(char(*__i)); |
| 1141 | } |
| 1142 | string_type __r; |
| 1143 | if (!__s.empty()) |
| 1144 | { |
| 1145 | __n = __get_collation_name(__n.c_str()); |
| 1146 | if (!__n.empty()) |
| 1147 | __r.assign(__n.begin(), __n.end()); |
| 1148 | else if (__s.size() <= 2) |
| 1149 | { |
| 1150 | __r = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1151 | if (__r.size() == 1 || __r.size() == 3) |
| 1152 | __r = __s; |
| 1153 | else |
| 1154 | __r.clear(); |
| 1155 | } |
| 1156 | } |
| 1157 | return __r; |
| 1158 | } |
| 1159 | |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1160 | // lookup_classname |
| 1161 | |
| 1162 | ctype_base::mask __get_classname(const char* __s, bool __icase); |
| 1163 | |
| 1164 | template <class _CharT> |
| 1165 | template <class _ForwardIterator> |
| 1166 | typename regex_traits<_CharT>::char_class_type |
| 1167 | regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, |
| 1168 | _ForwardIterator __l, |
| 1169 | bool __icase, char) const |
| 1170 | { |
| 1171 | string_type __s(__f, __l); |
| 1172 | __ct_->tolower(&__s[0], &__s[0] + __s.size()); |
| 1173 | return __get_classname(__s.c_str(), __icase); |
| 1174 | } |
| 1175 | |
| 1176 | template <class _CharT> |
| 1177 | template <class _ForwardIterator> |
| 1178 | typename regex_traits<_CharT>::char_class_type |
| 1179 | regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, |
| 1180 | _ForwardIterator __l, |
| 1181 | bool __icase, wchar_t) const |
| 1182 | { |
| 1183 | string_type __s(__f, __l); |
| 1184 | __ct_->tolower(&__s[0], &__s[0] + __s.size()); |
| 1185 | string __n; |
| 1186 | __n.reserve(__s.size()); |
| 1187 | for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); |
| 1188 | __i != __e; ++__i) |
| 1189 | { |
| 1190 | if (static_cast<unsigned>(*__i) >= 127) |
| 1191 | return char_class_type(); |
| 1192 | __n.push_back(char(*__i)); |
| 1193 | } |
| 1194 | return __get_classname(__n.c_str(), __icase); |
| 1195 | } |
| 1196 | |
| 1197 | template <class _CharT> |
| 1198 | bool |
| 1199 | regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const |
| 1200 | { |
| 1201 | if (__ct_->is(__m, __c)) |
| 1202 | return true; |
| 1203 | return (__c == '_' && (__m & __regex_word)); |
| 1204 | } |
| 1205 | |
| 1206 | template <class _CharT> |
| 1207 | int |
| 1208 | regex_traits<_CharT>::__value(unsigned char __ch, int __radix) |
| 1209 | { |
| 1210 | if ((__ch & 0xF8u) == 0x30) // '0' <= __ch && __ch <= '7' |
| 1211 | return __ch - '0'; |
| 1212 | if (__radix != 8) |
| 1213 | { |
| 1214 | if ((__ch & 0xFEu) == 0x38) // '8' <= __ch && __ch <= '9' |
| 1215 | return __ch - '0'; |
| 1216 | if (__radix == 16) |
| 1217 | { |
| 1218 | __ch |= 0x20; // tolower |
| 1219 | if ('a' <= __ch && __ch <= 'f') |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 1220 | return __ch - ('a' - 10); |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1221 | } |
| 1222 | } |
| 1223 | return -1; |
| 1224 | } |
| 1225 | |
| 1226 | template <class _CharT> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1227 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1228 | int |
| 1229 | regex_traits<_CharT>::__value(wchar_t __ch, int __radix) const |
| 1230 | { |
| 1231 | return __value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix); |
| 1232 | } |
| 1233 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1234 | template <class _CharT> class __node; |
| 1235 | |
| 1236 | template <class _BidirectionalIterator> class sub_match; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1237 | |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1238 | template <class _BidirectionalIterator, |
| 1239 | class _Allocator = allocator<sub_match<_BidirectionalIterator> > > |
| 1240 | class match_results; |
| 1241 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1242 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1243 | struct __state |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1244 | { |
| 1245 | enum |
| 1246 | { |
| 1247 | __end_state = -1000, |
| 1248 | __consume_input, // -999 |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1249 | __begin_marked_expr, // -998 |
| 1250 | __end_marked_expr, // -997 |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1251 | __pop_state, // -996 |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1252 | __accept_and_consume, // -995 |
| 1253 | __accept_but_not_consume, // -994 |
| 1254 | __reject, // -993 |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1255 | __split, |
| 1256 | __repeat |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1257 | }; |
| 1258 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1259 | int __do_; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1260 | const _CharT* __first_; |
| 1261 | const _CharT* __current_; |
| 1262 | const _CharT* __last_; |
| 1263 | vector<sub_match<const _CharT*> > __sub_matches_; |
| 1264 | vector<pair<size_t, const _CharT*> > __loop_data_; |
| 1265 | const __node<_CharT>* __node_; |
| 1266 | regex_constants::match_flag_type __flags_; |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 1267 | bool __at_first_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1268 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1269 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1270 | __state() |
| 1271 | : __do_(0), __first_(nullptr), __current_(nullptr), __last_(nullptr), |
| 1272 | __node_(nullptr), __flags_() {} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1273 | }; |
| 1274 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1275 | // __node |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1276 | |
| 1277 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1278 | class __node |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1279 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1280 | __node(const __node&); |
| 1281 | __node& operator=(const __node&); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1282 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1283 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1284 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1285 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1286 | __node() {} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1287 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1288 | virtual ~__node() {} |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1289 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1290 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1291 | virtual void __exec(__state&) const {}; |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1292 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1293 | virtual void __exec_split(bool, __state&) const {}; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1294 | }; |
| 1295 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1296 | // __end_state |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1297 | |
| 1298 | template <class _CharT> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1299 | class __end_state |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1300 | : public __node<_CharT> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1301 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1302 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1303 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1304 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1305 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1306 | __end_state() {} |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1307 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1308 | virtual void __exec(__state&) const; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1309 | }; |
| 1310 | |
| 1311 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1312 | void |
| 1313 | __end_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1314 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1315 | __s.__do_ = __state::__end_state; |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1316 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1317 | |
| 1318 | // __has_one_state |
| 1319 | |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1320 | template <class _CharT> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1321 | class __has_one_state |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1322 | : public __node<_CharT> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1323 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1324 | __node<_CharT>* __first_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1325 | |
| 1326 | public: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1327 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1328 | explicit __has_one_state(__node<_CharT>* __s) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1329 | : __first_(__s) {} |
| 1330 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1331 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1332 | __node<_CharT>* first() const {return __first_;} |
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 | __node<_CharT>*& first() {return __first_;} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1335 | }; |
| 1336 | |
| 1337 | // __owns_one_state |
| 1338 | |
| 1339 | template <class _CharT> |
| 1340 | class __owns_one_state |
| 1341 | : public __has_one_state<_CharT> |
| 1342 | { |
| 1343 | typedef __has_one_state<_CharT> base; |
| 1344 | |
| 1345 | public: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1346 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1347 | explicit __owns_one_state(__node<_CharT>* __s) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1348 | : base(__s) {} |
| 1349 | |
| 1350 | virtual ~__owns_one_state(); |
| 1351 | }; |
| 1352 | |
| 1353 | template <class _CharT> |
| 1354 | __owns_one_state<_CharT>::~__owns_one_state() |
| 1355 | { |
| 1356 | delete this->first(); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1357 | } |
| 1358 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1359 | // __empty_state |
| 1360 | |
| 1361 | template <class _CharT> |
| 1362 | class __empty_state |
| 1363 | : public __owns_one_state<_CharT> |
| 1364 | { |
| 1365 | typedef __owns_one_state<_CharT> base; |
| 1366 | |
| 1367 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1368 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1369 | |
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 __empty_state(__node<_CharT>* __s) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1372 | : base(__s) {} |
| 1373 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1374 | virtual void __exec(__state&) const; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1375 | }; |
| 1376 | |
| 1377 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1378 | void |
| 1379 | __empty_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1380 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1381 | __s.__do_ = __state::__accept_but_not_consume; |
| 1382 | __s.__node_ = this->first(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1383 | } |
| 1384 | |
| 1385 | // __empty_non_own_state |
| 1386 | |
| 1387 | template <class _CharT> |
| 1388 | class __empty_non_own_state |
| 1389 | : public __has_one_state<_CharT> |
| 1390 | { |
| 1391 | typedef __has_one_state<_CharT> base; |
| 1392 | |
| 1393 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1394 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1395 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1396 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1397 | explicit __empty_non_own_state(__node<_CharT>* __s) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1398 | : base(__s) {} |
| 1399 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1400 | virtual void __exec(__state&) const; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1401 | }; |
| 1402 | |
| 1403 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1404 | void |
| 1405 | __empty_non_own_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1406 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1407 | __s.__do_ = __state::__accept_but_not_consume; |
| 1408 | __s.__node_ = this->first(); |
| 1409 | } |
| 1410 | |
| 1411 | // __repeat_one_loop |
| 1412 | |
| 1413 | template <class _CharT> |
| 1414 | class __repeat_one_loop |
| 1415 | : public __has_one_state<_CharT> |
| 1416 | { |
| 1417 | typedef __has_one_state<_CharT> base; |
| 1418 | |
| 1419 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1420 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1421 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1422 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1423 | explicit __repeat_one_loop(__node<_CharT>* __s) |
| 1424 | : base(__s) {} |
| 1425 | |
| 1426 | virtual void __exec(__state&) const; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1427 | }; |
| 1428 | |
| 1429 | template <class _CharT> |
| 1430 | void |
| 1431 | __repeat_one_loop<_CharT>::__exec(__state& __s) const |
| 1432 | { |
| 1433 | __s.__do_ = __state::__repeat; |
| 1434 | __s.__node_ = this->first(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1435 | } |
| 1436 | |
| 1437 | // __owns_two_states |
| 1438 | |
| 1439 | template <class _CharT> |
| 1440 | class __owns_two_states |
| 1441 | : public __owns_one_state<_CharT> |
| 1442 | { |
| 1443 | typedef __owns_one_state<_CharT> base; |
| 1444 | |
| 1445 | base* __second_; |
| 1446 | |
| 1447 | public: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1448 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1449 | explicit __owns_two_states(__node<_CharT>* __s1, base* __s2) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1450 | : base(__s1), __second_(__s2) {} |
| 1451 | |
| 1452 | virtual ~__owns_two_states(); |
| 1453 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1454 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1455 | base* second() const {return __second_;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1456 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1457 | base*& second() {return __second_;} |
| 1458 | }; |
| 1459 | |
| 1460 | template <class _CharT> |
| 1461 | __owns_two_states<_CharT>::~__owns_two_states() |
| 1462 | { |
| 1463 | delete __second_; |
| 1464 | } |
| 1465 | |
| 1466 | // __loop |
| 1467 | |
| 1468 | template <class _CharT> |
| 1469 | class __loop |
| 1470 | : public __owns_two_states<_CharT> |
| 1471 | { |
| 1472 | typedef __owns_two_states<_CharT> base; |
| 1473 | |
| 1474 | size_t __min_; |
| 1475 | size_t __max_; |
| 1476 | unsigned __loop_id_; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1477 | unsigned __mexp_begin_; |
| 1478 | unsigned __mexp_end_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1479 | bool __greedy_; |
| 1480 | |
| 1481 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1482 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1483 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1484 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1485 | explicit __loop(unsigned __loop_id, |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1486 | __node<_CharT>* __s1, __owns_one_state<_CharT>* __s2, |
| 1487 | unsigned __mexp_begin, unsigned __mexp_end, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1488 | bool __greedy = true, |
| 1489 | size_t __min = 0, |
| 1490 | size_t __max = numeric_limits<size_t>::max()) |
| 1491 | : base(__s1, __s2), __min_(__min), __max_(__max), __loop_id_(__loop_id), |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1492 | __mexp_begin_(__mexp_begin), __mexp_end_(__mexp_end), |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1493 | __greedy_(__greedy) {} |
| 1494 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1495 | virtual void __exec(__state& __s) const; |
| 1496 | virtual void __exec_split(bool __second, __state& __s) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1497 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1498 | private: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1499 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1500 | void __init_repeat(__state& __s) const |
| 1501 | { |
| 1502 | __s.__loop_data_[__loop_id_].second = __s.__current_; |
| 1503 | for (size_t __i = __mexp_begin_-1; __i != __mexp_end_-1; ++__i) |
| 1504 | { |
| 1505 | __s.__sub_matches_[__i].first = __s.__last_; |
| 1506 | __s.__sub_matches_[__i].second = __s.__last_; |
| 1507 | __s.__sub_matches_[__i].matched = false; |
| 1508 | } |
| 1509 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1510 | }; |
| 1511 | |
| 1512 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1513 | void |
| 1514 | __loop<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1515 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1516 | if (__s.__do_ == __state::__repeat) |
| 1517 | { |
| 1518 | bool __do_repeat = ++__s.__loop_data_[__loop_id_].first < __max_; |
| 1519 | bool __do_alt = __s.__loop_data_[__loop_id_].first >= __min_; |
| 1520 | if (__do_repeat && __do_alt && |
| 1521 | __s.__loop_data_[__loop_id_].second == __s.__current_) |
| 1522 | __do_repeat = false; |
| 1523 | if (__do_repeat && __do_alt) |
| 1524 | __s.__do_ = __state::__split; |
| 1525 | else if (__do_repeat) |
| 1526 | { |
| 1527 | __s.__do_ = __state::__accept_but_not_consume; |
| 1528 | __s.__node_ = this->first(); |
| 1529 | __init_repeat(__s); |
| 1530 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1531 | else |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1532 | { |
| 1533 | __s.__do_ = __state::__accept_but_not_consume; |
| 1534 | __s.__node_ = this->second(); |
| 1535 | } |
| 1536 | } |
| 1537 | else |
| 1538 | { |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 1539 | __s.__loop_data_[__loop_id_].first = 0; |
| 1540 | bool __do_repeat = 0 < __max_; |
| 1541 | bool __do_alt = 0 >= __min_; |
| 1542 | if (__do_repeat && __do_alt) |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1543 | __s.__do_ = __state::__split; |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 1544 | else if (__do_repeat) |
| 1545 | { |
| 1546 | __s.__do_ = __state::__accept_but_not_consume; |
| 1547 | __s.__node_ = this->first(); |
| 1548 | __init_repeat(__s); |
| 1549 | } |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1550 | else |
| 1551 | { |
| 1552 | __s.__do_ = __state::__accept_but_not_consume; |
| 1553 | __s.__node_ = this->second(); |
| 1554 | } |
| 1555 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1556 | } |
| 1557 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1558 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1559 | void |
| 1560 | __loop<_CharT>::__exec_split(bool __second, __state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1561 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1562 | __s.__do_ = __state::__accept_but_not_consume; |
| 1563 | if (__greedy_ != __second) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1564 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1565 | __s.__node_ = this->first(); |
| 1566 | __init_repeat(__s); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1567 | } |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1568 | else |
| 1569 | __s.__node_ = this->second(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1570 | } |
| 1571 | |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1572 | // __alternate |
| 1573 | |
| 1574 | template <class _CharT> |
| 1575 | class __alternate |
| 1576 | : public __owns_two_states<_CharT> |
| 1577 | { |
| 1578 | typedef __owns_two_states<_CharT> base; |
| 1579 | |
| 1580 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1581 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1582 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1583 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1584 | explicit __alternate(__owns_one_state<_CharT>* __s1, |
| 1585 | __owns_one_state<_CharT>* __s2) |
| 1586 | : base(__s1, __s2) {} |
| 1587 | |
| 1588 | virtual void __exec(__state& __s) const; |
| 1589 | virtual void __exec_split(bool __second, __state& __s) const; |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1590 | }; |
| 1591 | |
| 1592 | template <class _CharT> |
| 1593 | void |
| 1594 | __alternate<_CharT>::__exec(__state& __s) const |
| 1595 | { |
| 1596 | __s.__do_ = __state::__split; |
| 1597 | } |
| 1598 | |
| 1599 | template <class _CharT> |
| 1600 | void |
| 1601 | __alternate<_CharT>::__exec_split(bool __second, __state& __s) const |
| 1602 | { |
| 1603 | __s.__do_ = __state::__accept_but_not_consume; |
Howard Hinnant | 1371b2e | 2010-07-22 14:12:20 +0000 | [diff] [blame] | 1604 | if (__second) |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1605 | __s.__node_ = this->second(); |
Howard Hinnant | 1371b2e | 2010-07-22 14:12:20 +0000 | [diff] [blame] | 1606 | else |
| 1607 | __s.__node_ = this->first(); |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1608 | } |
| 1609 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1610 | // __begin_marked_subexpression |
| 1611 | |
| 1612 | template <class _CharT> |
| 1613 | class __begin_marked_subexpression |
| 1614 | : public __owns_one_state<_CharT> |
| 1615 | { |
| 1616 | typedef __owns_one_state<_CharT> base; |
| 1617 | |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1618 | unsigned __mexp_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1619 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1620 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1621 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1622 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1623 | explicit __begin_marked_subexpression(unsigned __mexp, __node<_CharT>* __s) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1624 | : base(__s), __mexp_(__mexp) {} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1625 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1626 | virtual void __exec(__state&) const; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1627 | }; |
| 1628 | |
| 1629 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1630 | void |
| 1631 | __begin_marked_subexpression<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1632 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1633 | __s.__do_ = __state::__accept_but_not_consume; |
| 1634 | __s.__sub_matches_[__mexp_-1].first = __s.__current_; |
| 1635 | __s.__node_ = this->first(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1636 | } |
| 1637 | |
| 1638 | // __end_marked_subexpression |
| 1639 | |
| 1640 | template <class _CharT> |
| 1641 | class __end_marked_subexpression |
| 1642 | : public __owns_one_state<_CharT> |
| 1643 | { |
| 1644 | typedef __owns_one_state<_CharT> base; |
| 1645 | |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1646 | unsigned __mexp_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1647 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1648 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1649 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1650 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1651 | explicit __end_marked_subexpression(unsigned __mexp, __node<_CharT>* __s) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1652 | : base(__s), __mexp_(__mexp) {} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1653 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1654 | virtual void __exec(__state&) const; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1655 | }; |
| 1656 | |
| 1657 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1658 | void |
| 1659 | __end_marked_subexpression<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1660 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1661 | __s.__do_ = __state::__accept_but_not_consume; |
| 1662 | __s.__sub_matches_[__mexp_-1].second = __s.__current_; |
| 1663 | __s.__sub_matches_[__mexp_-1].matched = true; |
| 1664 | __s.__node_ = this->first(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1665 | } |
| 1666 | |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1667 | // __back_ref |
| 1668 | |
| 1669 | template <class _CharT> |
| 1670 | class __back_ref |
| 1671 | : public __owns_one_state<_CharT> |
| 1672 | { |
| 1673 | typedef __owns_one_state<_CharT> base; |
| 1674 | |
| 1675 | unsigned __mexp_; |
| 1676 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1677 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1678 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1679 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1680 | explicit __back_ref(unsigned __mexp, __node<_CharT>* __s) |
| 1681 | : base(__s), __mexp_(__mexp) {} |
| 1682 | |
| 1683 | virtual void __exec(__state&) const; |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1684 | }; |
| 1685 | |
| 1686 | template <class _CharT> |
| 1687 | void |
| 1688 | __back_ref<_CharT>::__exec(__state& __s) const |
| 1689 | { |
| 1690 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1691 | if (__sm.matched) |
| 1692 | { |
| 1693 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1694 | if (__s.__last_ - __s.__current_ >= __len && |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1695 | _VSTD::equal(__sm.first, __sm.second, __s.__current_)) |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1696 | { |
| 1697 | __s.__do_ = __state::__accept_but_not_consume; |
| 1698 | __s.__current_ += __len; |
| 1699 | __s.__node_ = this->first(); |
| 1700 | } |
| 1701 | else |
| 1702 | { |
| 1703 | __s.__do_ = __state::__reject; |
| 1704 | __s.__node_ = nullptr; |
| 1705 | } |
| 1706 | } |
| 1707 | else |
| 1708 | { |
| 1709 | __s.__do_ = __state::__reject; |
| 1710 | __s.__node_ = nullptr; |
| 1711 | } |
| 1712 | } |
| 1713 | |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1714 | // __back_ref_icase |
| 1715 | |
| 1716 | template <class _CharT, class _Traits> |
| 1717 | class __back_ref_icase |
| 1718 | : public __owns_one_state<_CharT> |
| 1719 | { |
| 1720 | typedef __owns_one_state<_CharT> base; |
| 1721 | |
| 1722 | _Traits __traits_; |
| 1723 | unsigned __mexp_; |
| 1724 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1725 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1726 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1727 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1728 | explicit __back_ref_icase(const _Traits& __traits, unsigned __mexp, |
| 1729 | __node<_CharT>* __s) |
| 1730 | : base(__s), __traits_(__traits), __mexp_(__mexp) {} |
| 1731 | |
| 1732 | virtual void __exec(__state&) const; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1733 | }; |
| 1734 | |
| 1735 | template <class _CharT, class _Traits> |
| 1736 | void |
| 1737 | __back_ref_icase<_CharT, _Traits>::__exec(__state& __s) const |
| 1738 | { |
| 1739 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1740 | if (__sm.matched) |
| 1741 | { |
| 1742 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1743 | if (__s.__last_ - __s.__current_ >= __len) |
| 1744 | { |
| 1745 | for (ptrdiff_t __i = 0; __i < __len; ++__i) |
| 1746 | { |
| 1747 | if (__traits_.translate_nocase(__sm.first[__i]) != |
| 1748 | __traits_.translate_nocase(__s.__current_[__i])) |
| 1749 | goto __not_equal; |
| 1750 | } |
| 1751 | __s.__do_ = __state::__accept_but_not_consume; |
| 1752 | __s.__current_ += __len; |
| 1753 | __s.__node_ = this->first(); |
| 1754 | } |
| 1755 | else |
| 1756 | { |
| 1757 | __s.__do_ = __state::__reject; |
| 1758 | __s.__node_ = nullptr; |
| 1759 | } |
| 1760 | } |
| 1761 | else |
| 1762 | { |
| 1763 | __not_equal: |
| 1764 | __s.__do_ = __state::__reject; |
| 1765 | __s.__node_ = nullptr; |
| 1766 | } |
| 1767 | } |
| 1768 | |
| 1769 | // __back_ref_collate |
| 1770 | |
| 1771 | template <class _CharT, class _Traits> |
| 1772 | class __back_ref_collate |
| 1773 | : public __owns_one_state<_CharT> |
| 1774 | { |
| 1775 | typedef __owns_one_state<_CharT> base; |
| 1776 | |
| 1777 | _Traits __traits_; |
| 1778 | unsigned __mexp_; |
| 1779 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1780 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1781 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1782 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1783 | explicit __back_ref_collate(const _Traits& __traits, unsigned __mexp, |
| 1784 | __node<_CharT>* __s) |
| 1785 | : base(__s), __traits_(__traits), __mexp_(__mexp) {} |
| 1786 | |
| 1787 | virtual void __exec(__state&) const; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1788 | }; |
| 1789 | |
| 1790 | template <class _CharT, class _Traits> |
| 1791 | void |
| 1792 | __back_ref_collate<_CharT, _Traits>::__exec(__state& __s) const |
| 1793 | { |
| 1794 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1795 | if (__sm.matched) |
| 1796 | { |
| 1797 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1798 | if (__s.__last_ - __s.__current_ >= __len) |
| 1799 | { |
| 1800 | for (ptrdiff_t __i = 0; __i < __len; ++__i) |
| 1801 | { |
| 1802 | if (__traits_.translate(__sm.first[__i]) != |
| 1803 | __traits_.translate(__s.__current_[__i])) |
| 1804 | goto __not_equal; |
| 1805 | } |
| 1806 | __s.__do_ = __state::__accept_but_not_consume; |
| 1807 | __s.__current_ += __len; |
| 1808 | __s.__node_ = this->first(); |
| 1809 | } |
| 1810 | else |
| 1811 | { |
| 1812 | __s.__do_ = __state::__reject; |
| 1813 | __s.__node_ = nullptr; |
| 1814 | } |
| 1815 | } |
| 1816 | else |
| 1817 | { |
| 1818 | __not_equal: |
| 1819 | __s.__do_ = __state::__reject; |
| 1820 | __s.__node_ = nullptr; |
| 1821 | } |
| 1822 | } |
| 1823 | |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1824 | // __word_boundary |
| 1825 | |
| 1826 | template <class _CharT, class _Traits> |
| 1827 | class __word_boundary |
| 1828 | : public __owns_one_state<_CharT> |
| 1829 | { |
| 1830 | typedef __owns_one_state<_CharT> base; |
| 1831 | |
| 1832 | _Traits __traits_; |
| 1833 | bool __invert_; |
| 1834 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1835 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1836 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1837 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1838 | explicit __word_boundary(const _Traits& __traits, bool __invert, |
| 1839 | __node<_CharT>* __s) |
| 1840 | : base(__s), __traits_(__traits), __invert_(__invert) {} |
| 1841 | |
| 1842 | virtual void __exec(__state&) const; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1843 | }; |
| 1844 | |
| 1845 | template <class _CharT, class _Traits> |
| 1846 | void |
| 1847 | __word_boundary<_CharT, _Traits>::__exec(__state& __s) const |
| 1848 | { |
| 1849 | bool __is_word_b = false; |
| 1850 | if (__s.__first_ != __s.__last_) |
| 1851 | { |
| 1852 | if (__s.__current_ == __s.__last_) |
| 1853 | { |
| 1854 | if (!(__s.__flags_ & regex_constants::match_not_eow)) |
| 1855 | { |
| 1856 | _CharT __c = __s.__current_[-1]; |
| 1857 | __is_word_b = __c == '_' || |
| 1858 | __traits_.isctype(__c, ctype_base::alnum); |
| 1859 | } |
| 1860 | } |
Howard Hinnant | f3dcca0 | 2010-07-29 15:17:28 +0000 | [diff] [blame] | 1861 | else if (__s.__current_ == __s.__first_ && |
| 1862 | !(__s.__flags_ & regex_constants::match_prev_avail)) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1863 | { |
| 1864 | if (!(__s.__flags_ & regex_constants::match_not_bow)) |
| 1865 | { |
| 1866 | _CharT __c = *__s.__current_; |
| 1867 | __is_word_b = __c == '_' || |
| 1868 | __traits_.isctype(__c, ctype_base::alnum); |
| 1869 | } |
| 1870 | } |
| 1871 | else |
| 1872 | { |
| 1873 | _CharT __c1 = __s.__current_[-1]; |
| 1874 | _CharT __c2 = *__s.__current_; |
| 1875 | bool __is_c1_b = __c1 == '_' || |
| 1876 | __traits_.isctype(__c1, ctype_base::alnum); |
| 1877 | bool __is_c2_b = __c2 == '_' || |
| 1878 | __traits_.isctype(__c2, ctype_base::alnum); |
| 1879 | __is_word_b = __is_c1_b != __is_c2_b; |
| 1880 | } |
| 1881 | } |
| 1882 | if (__is_word_b != __invert_) |
| 1883 | { |
| 1884 | __s.__do_ = __state::__accept_but_not_consume; |
| 1885 | __s.__node_ = this->first(); |
| 1886 | } |
| 1887 | else |
| 1888 | { |
| 1889 | __s.__do_ = __state::__reject; |
| 1890 | __s.__node_ = nullptr; |
| 1891 | } |
| 1892 | } |
| 1893 | |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 1894 | // __l_anchor |
| 1895 | |
| 1896 | template <class _CharT> |
| 1897 | class __l_anchor |
| 1898 | : public __owns_one_state<_CharT> |
| 1899 | { |
| 1900 | typedef __owns_one_state<_CharT> base; |
| 1901 | |
| 1902 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1903 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 1904 | |
| 1905 | _LIBCPP_INLINE_VISIBILITY |
| 1906 | __l_anchor(__node<_CharT>* __s) |
| 1907 | : base(__s) {} |
| 1908 | |
| 1909 | virtual void __exec(__state&) const; |
| 1910 | }; |
| 1911 | |
| 1912 | template <class _CharT> |
| 1913 | void |
| 1914 | __l_anchor<_CharT>::__exec(__state& __s) const |
| 1915 | { |
| 1916 | if (__s.__at_first_ && __s.__current_ == __s.__first_) |
| 1917 | { |
| 1918 | __s.__do_ = __state::__accept_but_not_consume; |
| 1919 | __s.__node_ = this->first(); |
| 1920 | } |
| 1921 | else |
| 1922 | { |
| 1923 | __s.__do_ = __state::__reject; |
| 1924 | __s.__node_ = nullptr; |
| 1925 | } |
| 1926 | } |
| 1927 | |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 1928 | // __r_anchor |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1929 | |
| 1930 | template <class _CharT> |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 1931 | class __r_anchor |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1932 | : public __owns_one_state<_CharT> |
| 1933 | { |
| 1934 | typedef __owns_one_state<_CharT> base; |
| 1935 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1936 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1937 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1938 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1939 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1940 | __r_anchor(__node<_CharT>* __s) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 1941 | : base(__s) {} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1942 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1943 | virtual void __exec(__state&) const; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1944 | }; |
| 1945 | |
| 1946 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1947 | void |
| 1948 | __r_anchor<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1949 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1950 | if (__s.__current_ == __s.__last_) |
| 1951 | { |
| 1952 | __s.__do_ = __state::__accept_but_not_consume; |
| 1953 | __s.__node_ = this->first(); |
| 1954 | } |
| 1955 | else |
| 1956 | { |
| 1957 | __s.__do_ = __state::__reject; |
| 1958 | __s.__node_ = nullptr; |
| 1959 | } |
| 1960 | } |
| 1961 | |
| 1962 | // __match_any |
| 1963 | |
| 1964 | template <class _CharT> |
| 1965 | class __match_any |
| 1966 | : public __owns_one_state<_CharT> |
| 1967 | { |
| 1968 | typedef __owns_one_state<_CharT> base; |
| 1969 | |
| 1970 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1971 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1972 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1973 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1974 | __match_any(__node<_CharT>* __s) |
| 1975 | : base(__s) {} |
| 1976 | |
| 1977 | virtual void __exec(__state&) const; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1978 | }; |
| 1979 | |
| 1980 | template <class _CharT> |
| 1981 | void |
| 1982 | __match_any<_CharT>::__exec(__state& __s) const |
| 1983 | { |
| 1984 | if (__s.__current_ != __s.__last_ && *__s.__current_ != 0) |
| 1985 | { |
| 1986 | __s.__do_ = __state::__accept_and_consume; |
| 1987 | ++__s.__current_; |
| 1988 | __s.__node_ = this->first(); |
| 1989 | } |
| 1990 | else |
| 1991 | { |
| 1992 | __s.__do_ = __state::__reject; |
| 1993 | __s.__node_ = nullptr; |
| 1994 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1995 | } |
| 1996 | |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1997 | // __match_any_but_newline |
| 1998 | |
| 1999 | template <class _CharT> |
| 2000 | class __match_any_but_newline |
| 2001 | : public __owns_one_state<_CharT> |
| 2002 | { |
| 2003 | typedef __owns_one_state<_CharT> base; |
| 2004 | |
| 2005 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2006 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2007 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2008 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2009 | __match_any_but_newline(__node<_CharT>* __s) |
| 2010 | : base(__s) {} |
| 2011 | |
| 2012 | virtual void __exec(__state&) const; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2013 | }; |
| 2014 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2015 | // __match_char |
| 2016 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2017 | template <class _CharT> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2018 | class __match_char |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2019 | : public __owns_one_state<_CharT> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2020 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2021 | typedef __owns_one_state<_CharT> base; |
| 2022 | |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2023 | _CharT __c_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2024 | |
| 2025 | __match_char(const __match_char&); |
| 2026 | __match_char& operator=(const __match_char&); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2027 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2028 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2029 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2030 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2031 | __match_char(_CharT __c, __node<_CharT>* __s) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2032 | : base(__s), __c_(__c) {} |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2033 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2034 | virtual void __exec(__state&) const; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2035 | }; |
| 2036 | |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2037 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2038 | void |
| 2039 | __match_char<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2040 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2041 | if (__s.__current_ != __s.__last_ && *__s.__current_ == __c_) |
| 2042 | { |
| 2043 | __s.__do_ = __state::__accept_and_consume; |
| 2044 | ++__s.__current_; |
| 2045 | __s.__node_ = this->first(); |
| 2046 | } |
| 2047 | else |
| 2048 | { |
| 2049 | __s.__do_ = __state::__reject; |
| 2050 | __s.__node_ = nullptr; |
| 2051 | } |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2052 | } |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2053 | |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2054 | // __match_char_icase |
| 2055 | |
| 2056 | template <class _CharT, class _Traits> |
| 2057 | class __match_char_icase |
| 2058 | : public __owns_one_state<_CharT> |
| 2059 | { |
| 2060 | typedef __owns_one_state<_CharT> base; |
| 2061 | |
| 2062 | _Traits __traits_; |
| 2063 | _CharT __c_; |
| 2064 | |
| 2065 | __match_char_icase(const __match_char_icase&); |
| 2066 | __match_char_icase& operator=(const __match_char_icase&); |
| 2067 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2068 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2069 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2070 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2071 | __match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s) |
| 2072 | : base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {} |
| 2073 | |
| 2074 | virtual void __exec(__state&) const; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2075 | }; |
| 2076 | |
| 2077 | template <class _CharT, class _Traits> |
| 2078 | void |
| 2079 | __match_char_icase<_CharT, _Traits>::__exec(__state& __s) const |
| 2080 | { |
| 2081 | if (__s.__current_ != __s.__last_ && |
| 2082 | __traits_.translate_nocase(*__s.__current_) == __c_) |
| 2083 | { |
| 2084 | __s.__do_ = __state::__accept_and_consume; |
| 2085 | ++__s.__current_; |
| 2086 | __s.__node_ = this->first(); |
| 2087 | } |
| 2088 | else |
| 2089 | { |
| 2090 | __s.__do_ = __state::__reject; |
| 2091 | __s.__node_ = nullptr; |
| 2092 | } |
| 2093 | } |
| 2094 | |
| 2095 | // __match_char_collate |
| 2096 | |
| 2097 | template <class _CharT, class _Traits> |
| 2098 | class __match_char_collate |
| 2099 | : public __owns_one_state<_CharT> |
| 2100 | { |
| 2101 | typedef __owns_one_state<_CharT> base; |
| 2102 | |
| 2103 | _Traits __traits_; |
| 2104 | _CharT __c_; |
| 2105 | |
| 2106 | __match_char_collate(const __match_char_collate&); |
| 2107 | __match_char_collate& operator=(const __match_char_collate&); |
| 2108 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2109 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2110 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2111 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2112 | __match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s) |
| 2113 | : base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {} |
| 2114 | |
| 2115 | virtual void __exec(__state&) const; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2116 | }; |
| 2117 | |
| 2118 | template <class _CharT, class _Traits> |
| 2119 | void |
| 2120 | __match_char_collate<_CharT, _Traits>::__exec(__state& __s) const |
| 2121 | { |
| 2122 | if (__s.__current_ != __s.__last_ && |
| 2123 | __traits_.translate(*__s.__current_) == __c_) |
| 2124 | { |
| 2125 | __s.__do_ = __state::__accept_and_consume; |
| 2126 | ++__s.__current_; |
| 2127 | __s.__node_ = this->first(); |
| 2128 | } |
| 2129 | else |
| 2130 | { |
| 2131 | __s.__do_ = __state::__reject; |
| 2132 | __s.__node_ = nullptr; |
| 2133 | } |
| 2134 | } |
| 2135 | |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2136 | // __bracket_expression |
| 2137 | |
| 2138 | template <class _CharT, class _Traits> |
| 2139 | class __bracket_expression |
| 2140 | : public __owns_one_state<_CharT> |
| 2141 | { |
| 2142 | typedef __owns_one_state<_CharT> base; |
| 2143 | typedef typename _Traits::string_type string_type; |
| 2144 | |
| 2145 | _Traits __traits_; |
| 2146 | vector<_CharT> __chars_; |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2147 | vector<_CharT> __neg_chars_; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2148 | vector<pair<string_type, string_type> > __ranges_; |
| 2149 | vector<pair<_CharT, _CharT> > __digraphs_; |
| 2150 | vector<string_type> __equivalences_; |
| 2151 | ctype_base::mask __mask_; |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2152 | ctype_base::mask __neg_mask_; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2153 | bool __negate_; |
| 2154 | bool __icase_; |
| 2155 | bool __collate_; |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2156 | bool __might_have_digraph_; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2157 | |
| 2158 | __bracket_expression(const __bracket_expression&); |
| 2159 | __bracket_expression& operator=(const __bracket_expression&); |
| 2160 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2161 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2162 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2163 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2164 | __bracket_expression(const _Traits& __traits, __node<_CharT>* __s, |
| 2165 | bool __negate, bool __icase, bool __collate) |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2166 | : base(__s), __traits_(__traits), __mask_(), __neg_mask_(), |
| 2167 | __negate_(__negate), __icase_(__icase), __collate_(__collate), |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2168 | __might_have_digraph_(__traits_.getloc().name() != "C") {} |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2169 | |
| 2170 | virtual void __exec(__state&) const; |
| 2171 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2172 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2173 | bool __negated() const {return __negate_;} |
| 2174 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2175 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2176 | void __add_char(_CharT __c) |
| 2177 | { |
| 2178 | if (__icase_) |
| 2179 | __chars_.push_back(__traits_.translate_nocase(__c)); |
| 2180 | else if (__collate_) |
| 2181 | __chars_.push_back(__traits_.translate(__c)); |
| 2182 | else |
| 2183 | __chars_.push_back(__c); |
| 2184 | } |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2185 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2186 | void __add_neg_char(_CharT __c) |
| 2187 | { |
| 2188 | if (__icase_) |
| 2189 | __neg_chars_.push_back(__traits_.translate_nocase(__c)); |
| 2190 | else if (__collate_) |
| 2191 | __neg_chars_.push_back(__traits_.translate(__c)); |
| 2192 | else |
| 2193 | __neg_chars_.push_back(__c); |
| 2194 | } |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2195 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2196 | void __add_range(string_type __b, string_type __e) |
| 2197 | { |
| 2198 | if (__collate_) |
| 2199 | { |
| 2200 | if (__icase_) |
| 2201 | { |
| 2202 | for (size_t __i = 0; __i < __b.size(); ++__i) |
| 2203 | __b[__i] = __traits_.translate_nocase(__b[__i]); |
| 2204 | for (size_t __i = 0; __i < __e.size(); ++__i) |
| 2205 | __e[__i] = __traits_.translate_nocase(__e[__i]); |
| 2206 | } |
| 2207 | else |
| 2208 | { |
| 2209 | for (size_t __i = 0; __i < __b.size(); ++__i) |
| 2210 | __b[__i] = __traits_.translate(__b[__i]); |
| 2211 | for (size_t __i = 0; __i < __e.size(); ++__i) |
| 2212 | __e[__i] = __traits_.translate(__e[__i]); |
| 2213 | } |
| 2214 | __ranges_.push_back(make_pair( |
| 2215 | __traits_.transform(__b.begin(), __b.end()), |
| 2216 | __traits_.transform(__e.begin(), __e.end()))); |
| 2217 | } |
| 2218 | else |
| 2219 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2220 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2221 | if (__b.size() != 1 || __e.size() != 1) |
| 2222 | throw regex_error(regex_constants::error_collate); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2223 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2224 | if (__icase_) |
| 2225 | { |
| 2226 | __b[0] = __traits_.translate_nocase(__b[0]); |
| 2227 | __e[0] = __traits_.translate_nocase(__e[0]); |
| 2228 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2229 | __ranges_.push_back(make_pair(_VSTD::move(__b), _VSTD::move(__e))); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2230 | } |
| 2231 | } |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2232 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2233 | void __add_digraph(_CharT __c1, _CharT __c2) |
| 2234 | { |
| 2235 | if (__icase_) |
| 2236 | __digraphs_.push_back(make_pair(__traits_.translate_nocase(__c1), |
| 2237 | __traits_.translate_nocase(__c2))); |
| 2238 | else if (__collate_) |
| 2239 | __digraphs_.push_back(make_pair(__traits_.translate(__c1), |
| 2240 | __traits_.translate(__c2))); |
| 2241 | else |
| 2242 | __digraphs_.push_back(make_pair(__c1, __c2)); |
| 2243 | } |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2244 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2245 | void __add_equivalence(const string_type& __s) |
| 2246 | {__equivalences_.push_back(__s);} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2247 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2248 | void __add_class(ctype_base::mask __mask) |
| 2249 | {__mask_ |= __mask;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2250 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2251 | void __add_neg_class(ctype_base::mask __mask) |
| 2252 | {__neg_mask_ |= __mask;} |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2253 | }; |
| 2254 | |
| 2255 | template <class _CharT, class _Traits> |
| 2256 | void |
| 2257 | __bracket_expression<_CharT, _Traits>::__exec(__state& __s) const |
| 2258 | { |
| 2259 | bool __found = false; |
| 2260 | unsigned __consumed = 0; |
| 2261 | if (__s.__current_ != __s.__last_) |
| 2262 | { |
| 2263 | ++__consumed; |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2264 | if (__might_have_digraph_) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2265 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2266 | const _CharT* __next = _VSTD::next(__s.__current_); |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2267 | if (__next != __s.__last_) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2268 | { |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2269 | pair<_CharT, _CharT> __ch2(*__s.__current_, *__next); |
| 2270 | if (__icase_) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2271 | { |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2272 | __ch2.first = __traits_.translate_nocase(__ch2.first); |
| 2273 | __ch2.second = __traits_.translate_nocase(__ch2.second); |
| 2274 | } |
| 2275 | else if (__collate_) |
| 2276 | { |
| 2277 | __ch2.first = __traits_.translate(__ch2.first); |
| 2278 | __ch2.second = __traits_.translate(__ch2.second); |
| 2279 | } |
| 2280 | if (!__traits_.lookup_collatename(&__ch2.first, &__ch2.first+2).empty()) |
| 2281 | { |
| 2282 | // __ch2 is a digraph in this locale |
| 2283 | ++__consumed; |
| 2284 | for (size_t __i = 0; __i < __digraphs_.size(); ++__i) |
| 2285 | { |
| 2286 | if (__ch2 == __digraphs_[__i]) |
| 2287 | { |
| 2288 | __found = true; |
| 2289 | goto __exit; |
| 2290 | } |
| 2291 | } |
| 2292 | if (__collate_ && !__ranges_.empty()) |
| 2293 | { |
| 2294 | string_type __s2 = __traits_.transform(&__ch2.first, |
| 2295 | &__ch2.first + 2); |
| 2296 | for (size_t __i = 0; __i < __ranges_.size(); ++__i) |
| 2297 | { |
| 2298 | if (__ranges_[__i].first <= __s2 && |
| 2299 | __s2 <= __ranges_[__i].second) |
| 2300 | { |
| 2301 | __found = true; |
| 2302 | goto __exit; |
| 2303 | } |
| 2304 | } |
| 2305 | } |
| 2306 | if (!__equivalences_.empty()) |
| 2307 | { |
| 2308 | string_type __s2 = __traits_.transform_primary(&__ch2.first, |
| 2309 | &__ch2.first + 2); |
| 2310 | for (size_t __i = 0; __i < __equivalences_.size(); ++__i) |
| 2311 | { |
| 2312 | if (__s2 == __equivalences_[__i]) |
| 2313 | { |
| 2314 | __found = true; |
| 2315 | goto __exit; |
| 2316 | } |
| 2317 | } |
| 2318 | } |
| 2319 | if (__traits_.isctype(__ch2.first, __mask_) && |
| 2320 | __traits_.isctype(__ch2.second, __mask_)) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2321 | { |
| 2322 | __found = true; |
| 2323 | goto __exit; |
| 2324 | } |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2325 | if (!__traits_.isctype(__ch2.first, __neg_mask_) && |
| 2326 | !__traits_.isctype(__ch2.second, __neg_mask_)) |
| 2327 | { |
| 2328 | __found = true; |
| 2329 | goto __exit; |
| 2330 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2331 | goto __exit; |
| 2332 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2333 | } |
| 2334 | } |
| 2335 | // test *__s.__current_ as not a digraph |
| 2336 | _CharT __ch = *__s.__current_; |
| 2337 | if (__icase_) |
| 2338 | __ch = __traits_.translate_nocase(__ch); |
| 2339 | else if (__collate_) |
| 2340 | __ch = __traits_.translate(__ch); |
| 2341 | for (size_t __i = 0; __i < __chars_.size(); ++__i) |
| 2342 | { |
| 2343 | if (__ch == __chars_[__i]) |
| 2344 | { |
| 2345 | __found = true; |
| 2346 | goto __exit; |
| 2347 | } |
| 2348 | } |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2349 | if (!__neg_chars_.empty()) |
| 2350 | { |
| 2351 | for (size_t __i = 0; __i < __neg_chars_.size(); ++__i) |
| 2352 | { |
| 2353 | if (__ch == __neg_chars_[__i]) |
| 2354 | goto __is_neg_char; |
| 2355 | } |
| 2356 | __found = true; |
| 2357 | goto __exit; |
| 2358 | } |
| 2359 | __is_neg_char: |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2360 | if (!__ranges_.empty()) |
| 2361 | { |
| 2362 | string_type __s2 = __collate_ ? |
| 2363 | __traits_.transform(&__ch, &__ch + 1) : |
| 2364 | string_type(1, __ch); |
| 2365 | for (size_t __i = 0; __i < __ranges_.size(); ++__i) |
| 2366 | { |
| 2367 | if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second) |
| 2368 | { |
| 2369 | __found = true; |
| 2370 | goto __exit; |
| 2371 | } |
| 2372 | } |
| 2373 | } |
| 2374 | if (!__equivalences_.empty()) |
| 2375 | { |
| 2376 | string_type __s2 = __traits_.transform_primary(&__ch, &__ch + 1); |
| 2377 | for (size_t __i = 0; __i < __equivalences_.size(); ++__i) |
| 2378 | { |
| 2379 | if (__s2 == __equivalences_[__i]) |
| 2380 | { |
| 2381 | __found = true; |
| 2382 | goto __exit; |
| 2383 | } |
| 2384 | } |
| 2385 | } |
| 2386 | if (__traits_.isctype(__ch, __mask_)) |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2387 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2388 | __found = true; |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2389 | goto __exit; |
| 2390 | } |
| 2391 | if (__neg_mask_ && !__traits_.isctype(__ch, __neg_mask_)) |
| 2392 | { |
| 2393 | __found = true; |
| 2394 | goto __exit; |
| 2395 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2396 | } |
| 2397 | else |
| 2398 | __found = __negate_; // force reject |
| 2399 | __exit: |
| 2400 | if (__found != __negate_) |
| 2401 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2402 | __s.__do_ = __state::__accept_and_consume; |
| 2403 | __s.__current_ += __consumed; |
| 2404 | __s.__node_ = this->first(); |
| 2405 | } |
| 2406 | else |
| 2407 | { |
| 2408 | __s.__do_ = __state::__reject; |
| 2409 | __s.__node_ = nullptr; |
| 2410 | } |
| 2411 | } |
| 2412 | |
Howard Hinnant | 2b1b2d4 | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 2413 | template <class _CharT, class _Traits> class __lookahead; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2414 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2415 | template <class _CharT, class _Traits = regex_traits<_CharT> > |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2416 | class _LIBCPP_VISIBLE basic_regex |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2417 | { |
| 2418 | public: |
| 2419 | // types: |
| 2420 | typedef _CharT value_type; |
| 2421 | typedef regex_constants::syntax_option_type flag_type; |
| 2422 | typedef typename _Traits::locale_type locale_type; |
| 2423 | |
| 2424 | private: |
| 2425 | _Traits __traits_; |
| 2426 | flag_type __flags_; |
| 2427 | unsigned __marked_count_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2428 | unsigned __loop_count_; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2429 | int __open_count_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2430 | shared_ptr<__empty_state<_CharT> > __start_; |
| 2431 | __owns_one_state<_CharT>* __end_; |
| 2432 | |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2433 | typedef _VSTD::__state<_CharT> __state; |
| 2434 | typedef _VSTD::__node<_CharT> __node; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2435 | |
| 2436 | public: |
| 2437 | // constants: |
| 2438 | static const/*expr*/ regex_constants::syntax_option_type icase = regex_constants::icase; |
| 2439 | static const/*expr*/ regex_constants::syntax_option_type nosubs = regex_constants::nosubs; |
| 2440 | static const/*expr*/ regex_constants::syntax_option_type optimize = regex_constants::optimize; |
| 2441 | static const/*expr*/ regex_constants::syntax_option_type collate = regex_constants::collate; |
| 2442 | static const/*expr*/ regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript; |
| 2443 | static const/*expr*/ regex_constants::syntax_option_type basic = regex_constants::basic; |
| 2444 | static const/*expr*/ regex_constants::syntax_option_type extended = regex_constants::extended; |
| 2445 | static const/*expr*/ regex_constants::syntax_option_type awk = regex_constants::awk; |
| 2446 | static const/*expr*/ regex_constants::syntax_option_type grep = regex_constants::grep; |
| 2447 | static const/*expr*/ regex_constants::syntax_option_type egrep = regex_constants::egrep; |
| 2448 | |
| 2449 | // construct/copy/destroy: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2450 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2451 | basic_regex() |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2452 | : __flags_(), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2453 | __end_(0) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2454 | {} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2455 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2456 | 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] | 2457 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2458 | __end_(0) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2459 | {__parse(__p, __p + __traits_.length(__p));} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2460 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2461 | basic_regex(const value_type* __p, size_t __len, flag_type __f) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2462 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2463 | __end_(0) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2464 | {__parse(__p, __p + __len);} |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2465 | // basic_regex(const basic_regex&) = default; |
| 2466 | // basic_regex(basic_regex&&) = default; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2467 | template <class _ST, class _SA> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2468 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2469 | explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p, |
| 2470 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2471 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2472 | __end_(0) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2473 | {__parse(__p.begin(), __p.end());} |
| 2474 | template <class _ForwardIterator> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2475 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2476 | basic_regex(_ForwardIterator __first, _ForwardIterator __last, |
| 2477 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2478 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2479 | __end_(0) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2480 | {__parse(__first, __last);} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2481 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2482 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2483 | basic_regex(initializer_list<value_type> __il, |
| 2484 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2485 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2486 | __end_(0) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2487 | {__parse(__il.begin(), __il.end());} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2488 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2489 | |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2490 | // ~basic_regex() = default; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2491 | |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2492 | // basic_regex& operator=(const basic_regex&) = default; |
| 2493 | // basic_regex& operator=(basic_regex&&) = default; |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2494 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2495 | basic_regex& operator=(const value_type* __p) |
| 2496 | {return assign(__p);} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2497 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2498 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2499 | basic_regex& operator=(initializer_list<value_type> __il) |
| 2500 | {return assign(__il);} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2501 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2502 | template <class _ST, class _SA> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2503 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2504 | basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p) |
| 2505 | {return assign(__p);} |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2506 | |
| 2507 | // assign: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2508 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2509 | basic_regex& assign(const basic_regex& __that) |
| 2510 | {return *this = __that;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2511 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2512 | basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript) |
| 2513 | {return assign(__p, __p + __traits_.length(__p), __f);} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2514 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2515 | basic_regex& assign(const value_type* __p, size_t __len, flag_type __f) |
| 2516 | {return assign(__p, __p + __len, __f);} |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2517 | template <class _ST, class _SA> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2518 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2519 | basic_regex& assign(const basic_string<value_type, _ST, _SA>& __s, |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2520 | flag_type __f = regex_constants::ECMAScript) |
| 2521 | {return assign(__s.begin(), __s.end(), __f);} |
| 2522 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2523 | template <class _InputIterator> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2524 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2525 | typename enable_if |
| 2526 | < |
| 2527 | __is_input_iterator <_InputIterator>::value && |
| 2528 | !__is_forward_iterator<_InputIterator>::value, |
| 2529 | basic_regex& |
| 2530 | >::type |
| 2531 | assign(_InputIterator __first, _InputIterator __last, |
| 2532 | flag_type __f = regex_constants::ECMAScript) |
| 2533 | { |
| 2534 | basic_string<_CharT> __t(__first, __last); |
| 2535 | return assign(__t.begin(), __t.end(), __f); |
| 2536 | } |
| 2537 | |
| 2538 | private: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2539 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2540 | void __member_init(flag_type __f) |
| 2541 | { |
| 2542 | __flags_ = __f; |
| 2543 | __marked_count_ = 0; |
| 2544 | __loop_count_ = 0; |
| 2545 | __open_count_ = 0; |
| 2546 | __end_ = nullptr; |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2547 | } |
| 2548 | public: |
| 2549 | |
| 2550 | template <class _ForwardIterator> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2551 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2552 | typename enable_if |
| 2553 | < |
| 2554 | __is_forward_iterator<_ForwardIterator>::value, |
| 2555 | basic_regex& |
| 2556 | >::type |
| 2557 | assign(_ForwardIterator __first, _ForwardIterator __last, |
| 2558 | flag_type __f = regex_constants::ECMAScript) |
| 2559 | { |
| 2560 | __member_init(__f); |
| 2561 | __parse(__first, __last); |
| 2562 | } |
| 2563 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2564 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 2565 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2566 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2567 | basic_regex& assign(initializer_list<value_type> __il, |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2568 | flag_type __f = regex_constants::ECMAScript) |
| 2569 | {return assign(__il.begin(), __il.end(), __f);} |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2570 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2571 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 2572 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2573 | // const operations: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2574 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2575 | unsigned mark_count() const {return __marked_count_;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2576 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2577 | flag_type flags() const {return __flags_;} |
| 2578 | |
| 2579 | // locale: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2580 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2581 | locale_type imbue(locale_type __loc) |
| 2582 | { |
| 2583 | __member_init(ECMAScript); |
| 2584 | __start_.reset(); |
| 2585 | return __traits_.imbue(__loc); |
| 2586 | } |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2587 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2588 | locale_type getloc() const {return __traits_.getloc();} |
| 2589 | |
| 2590 | // swap: |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2591 | void swap(basic_regex& __r); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2592 | |
| 2593 | private: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2594 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2595 | unsigned __loop_count() const {return __loop_count_;} |
| 2596 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2597 | template <class _ForwardIterator> |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2598 | _ForwardIterator |
| 2599 | __parse(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2600 | template <class _ForwardIterator> |
| 2601 | _ForwardIterator |
| 2602 | __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2603 | template <class _ForwardIterator> |
| 2604 | _ForwardIterator |
| 2605 | __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2606 | template <class _ForwardIterator> |
| 2607 | _ForwardIterator |
| 2608 | __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2609 | template <class _ForwardIterator> |
| 2610 | _ForwardIterator |
| 2611 | __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2612 | template <class _ForwardIterator> |
| 2613 | _ForwardIterator |
| 2614 | __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2615 | template <class _ForwardIterator> |
| 2616 | _ForwardIterator |
| 2617 | __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last); |
| 2618 | template <class _ForwardIterator> |
| 2619 | _ForwardIterator |
| 2620 | __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last); |
| 2621 | template <class _ForwardIterator> |
| 2622 | _ForwardIterator |
| 2623 | __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last); |
| 2624 | template <class _ForwardIterator> |
| 2625 | _ForwardIterator |
| 2626 | __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last); |
| 2627 | template <class _ForwardIterator> |
| 2628 | _ForwardIterator |
| 2629 | __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last); |
| 2630 | template <class _ForwardIterator> |
| 2631 | _ForwardIterator |
| 2632 | __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last); |
| 2633 | template <class _ForwardIterator> |
| 2634 | _ForwardIterator |
| 2635 | __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last); |
| 2636 | template <class _ForwardIterator> |
| 2637 | _ForwardIterator |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2638 | __parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last, |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2639 | __owns_one_state<_CharT>* __s, |
| 2640 | unsigned __mexp_begin, unsigned __mexp_end); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2641 | template <class _ForwardIterator> |
| 2642 | _ForwardIterator |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 2643 | __parse_ERE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last, |
| 2644 | __owns_one_state<_CharT>* __s, |
| 2645 | unsigned __mexp_begin, unsigned __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2646 | template <class _ForwardIterator> |
| 2647 | _ForwardIterator |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2648 | __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2649 | template <class _ForwardIterator> |
| 2650 | _ForwardIterator |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2651 | __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last, |
| 2652 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2653 | template <class _ForwardIterator> |
| 2654 | _ForwardIterator |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2655 | __parse_expression_term(_ForwardIterator __first, _ForwardIterator __last, |
| 2656 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2657 | template <class _ForwardIterator> |
| 2658 | _ForwardIterator |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2659 | __parse_equivalence_class(_ForwardIterator __first, _ForwardIterator __last, |
| 2660 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2661 | template <class _ForwardIterator> |
| 2662 | _ForwardIterator |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2663 | __parse_character_class(_ForwardIterator __first, _ForwardIterator __last, |
| 2664 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2665 | template <class _ForwardIterator> |
| 2666 | _ForwardIterator |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2667 | __parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last, |
| 2668 | basic_string<_CharT>& __col_sym); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2669 | template <class _ForwardIterator> |
| 2670 | _ForwardIterator |
| 2671 | __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2672 | template <class _ForwardIterator> |
| 2673 | _ForwardIterator |
| 2674 | __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2675 | template <class _ForwardIterator> |
| 2676 | _ForwardIterator |
| 2677 | __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last); |
| 2678 | template <class _ForwardIterator> |
| 2679 | _ForwardIterator |
| 2680 | __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2681 | template <class _ForwardIterator> |
| 2682 | _ForwardIterator |
| 2683 | __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last); |
| 2684 | template <class _ForwardIterator> |
| 2685 | _ForwardIterator |
| 2686 | __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last); |
| 2687 | template <class _ForwardIterator> |
| 2688 | _ForwardIterator |
| 2689 | __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 2690 | template <class _ForwardIterator> |
| 2691 | _ForwardIterator |
| 2692 | __parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2693 | template <class _ForwardIterator> |
| 2694 | _ForwardIterator |
| 2695 | __parse_alternative(_ForwardIterator __first, _ForwardIterator __last); |
| 2696 | template <class _ForwardIterator> |
| 2697 | _ForwardIterator |
| 2698 | __parse_term(_ForwardIterator __first, _ForwardIterator __last); |
| 2699 | template <class _ForwardIterator> |
| 2700 | _ForwardIterator |
| 2701 | __parse_assertion(_ForwardIterator __first, _ForwardIterator __last); |
| 2702 | template <class _ForwardIterator> |
| 2703 | _ForwardIterator |
| 2704 | __parse_atom(_ForwardIterator __first, _ForwardIterator __last); |
| 2705 | template <class _ForwardIterator> |
| 2706 | _ForwardIterator |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2707 | __parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2708 | template <class _ForwardIterator> |
| 2709 | _ForwardIterator |
| 2710 | __parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2711 | template <class _ForwardIterator> |
| 2712 | _ForwardIterator |
| 2713 | __parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2714 | template <class _ForwardIterator> |
| 2715 | _ForwardIterator |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2716 | __parse_character_escape(_ForwardIterator __first, _ForwardIterator __last, |
| 2717 | basic_string<_CharT>* __str = nullptr); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2718 | template <class _ForwardIterator> |
| 2719 | _ForwardIterator |
| 2720 | __parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 856846b | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 2721 | template <class _ForwardIterator> |
| 2722 | _ForwardIterator |
| 2723 | __parse_grep(_ForwardIterator __first, _ForwardIterator __last); |
| 2724 | template <class _ForwardIterator> |
| 2725 | _ForwardIterator |
| 2726 | __parse_egrep(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2727 | template <class _ForwardIterator> |
| 2728 | _ForwardIterator |
| 2729 | __parse_class_escape(_ForwardIterator __first, _ForwardIterator __last, |
| 2730 | basic_string<_CharT>& __str, |
| 2731 | __bracket_expression<_CharT, _Traits>* __ml); |
| 2732 | template <class _ForwardIterator> |
| 2733 | _ForwardIterator |
| 2734 | __parse_awk_escape(_ForwardIterator __first, _ForwardIterator __last, |
| 2735 | basic_string<_CharT>* __str = nullptr); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2736 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2737 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2738 | void __push_l_anchor(); |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2739 | void __push_r_anchor(); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2740 | void __push_match_any(); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2741 | void __push_match_any_but_newline(); |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2742 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2743 | void __push_greedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s, |
| 2744 | unsigned __mexp_begin = 0, unsigned __mexp_end = 0) |
| 2745 | {__push_loop(__min, numeric_limits<size_t>::max(), __s, |
| 2746 | __mexp_begin, __mexp_end);} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2747 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2748 | void __push_nongreedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s, |
| 2749 | unsigned __mexp_begin = 0, unsigned __mexp_end = 0) |
| 2750 | {__push_loop(__min, numeric_limits<size_t>::max(), __s, |
| 2751 | __mexp_begin, __mexp_end, false);} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2752 | void __push_loop(size_t __min, size_t __max, __owns_one_state<_CharT>* __s, |
| 2753 | size_t __mexp_begin = 0, size_t __mexp_end = 0, |
| 2754 | bool __greedy = true); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2755 | __bracket_expression<_CharT, _Traits>* __start_matching_list(bool __negate); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2756 | void __push_char(value_type __c); |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 2757 | void __push_back_ref(int __i); |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 2758 | void __push_alternation(__owns_one_state<_CharT>* __sa, |
| 2759 | __owns_one_state<_CharT>* __sb); |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2760 | void __push_begin_marked_subexpression(); |
| 2761 | void __push_end_marked_subexpression(unsigned); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 2762 | void __push_empty(); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2763 | void __push_word_boundary(bool); |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2764 | void __push_lookahead(const basic_regex&, bool); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2765 | |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2766 | template <class _Allocator> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2767 | bool |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2768 | __search(const _CharT* __first, const _CharT* __last, |
| 2769 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2770 | regex_constants::match_flag_type __flags) const; |
| 2771 | |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2772 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2773 | bool |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2774 | __match_at_start(const _CharT* __first, const _CharT* __last, |
| 2775 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2776 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2777 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2778 | bool |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2779 | __match_at_start_ecma(const _CharT* __first, const _CharT* __last, |
| 2780 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2781 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2782 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2783 | bool |
| 2784 | __match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last, |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2785 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2786 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2787 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2788 | bool |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2789 | __match_at_start_posix_subs(const _CharT* __first, const _CharT* __last, |
| 2790 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2791 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2792 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2793 | template <class _B, class _A, class _C, class _T> |
| 2794 | friend |
| 2795 | bool |
| 2796 | regex_search(_B, _B, match_results<_B, _A>&, const basic_regex<_C, _T>&, |
| 2797 | regex_constants::match_flag_type); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2798 | |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2799 | template <class _A, class _C, class _T> |
| 2800 | friend |
| 2801 | bool |
| 2802 | regex_search(const _C*, const _C*, match_results<const _C*, _A>&, |
| 2803 | const basic_regex<_C, _T>&, regex_constants::match_flag_type); |
| 2804 | |
| 2805 | template <class _B, class _C, class _T> |
| 2806 | friend |
| 2807 | bool |
| 2808 | regex_search(_B, _B, const basic_regex<_C, _T>&, |
| 2809 | regex_constants::match_flag_type); |
| 2810 | |
| 2811 | template <class _C, class _T> |
| 2812 | friend |
| 2813 | bool |
| 2814 | regex_search(const _C*, const _C*, |
| 2815 | const basic_regex<_C, _T>&, regex_constants::match_flag_type); |
| 2816 | |
| 2817 | template <class _C, class _A, class _T> |
| 2818 | friend |
| 2819 | bool |
| 2820 | regex_search(const _C*, match_results<const _C*, _A>&, const basic_regex<_C, _T>&, |
| 2821 | regex_constants::match_flag_type); |
| 2822 | |
| 2823 | template <class _ST, class _SA, class _C, class _T> |
| 2824 | friend |
| 2825 | bool |
| 2826 | regex_search(const basic_string<_C, _ST, _SA>& __s, |
| 2827 | const basic_regex<_C, _T>& __e, |
| 2828 | regex_constants::match_flag_type __flags); |
| 2829 | |
| 2830 | template <class _ST, class _SA, class _A, class _C, class _T> |
| 2831 | friend |
| 2832 | bool |
| 2833 | regex_search(const basic_string<_C, _ST, _SA>& __s, |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2834 | match_results<typename basic_string<_C, _ST, _SA>::const_iterator, _A>&, |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2835 | const basic_regex<_C, _T>& __e, |
| 2836 | regex_constants::match_flag_type __flags); |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2837 | |
| 2838 | template <class, class> friend class __lookahead; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2839 | }; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2840 | |
| 2841 | template <class _CharT, class _Traits> |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2842 | void |
| 2843 | basic_regex<_CharT, _Traits>::swap(basic_regex& __r) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2844 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2845 | using _VSTD::swap; |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2846 | swap(__traits_, __r.__traits_); |
| 2847 | swap(__flags_, __r.__flags_); |
| 2848 | swap(__marked_count_, __r.__marked_count_); |
| 2849 | swap(__loop_count_, __r.__loop_count_); |
| 2850 | swap(__open_count_, __r.__open_count_); |
| 2851 | swap(__start_, __r.__start_); |
| 2852 | swap(__end_, __r.__end_); |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2853 | } |
| 2854 | |
| 2855 | template <class _CharT, class _Traits> |
| 2856 | inline _LIBCPP_INLINE_VISIBILITY |
| 2857 | void |
| 2858 | swap(basic_regex<_CharT, _Traits>& __x, basic_regex<_CharT, _Traits>& __y) |
| 2859 | { |
| 2860 | return __x.swap(__y); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2861 | } |
| 2862 | |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2863 | // __lookahead |
| 2864 | |
| 2865 | template <class _CharT, class _Traits> |
| 2866 | class __lookahead |
| 2867 | : public __owns_one_state<_CharT> |
| 2868 | { |
| 2869 | typedef __owns_one_state<_CharT> base; |
| 2870 | |
| 2871 | basic_regex<_CharT, _Traits> __exp_; |
| 2872 | bool __invert_; |
| 2873 | |
| 2874 | __lookahead(const __lookahead&); |
| 2875 | __lookahead& operator=(const __lookahead&); |
| 2876 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2877 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2878 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2879 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2880 | __lookahead(const basic_regex<_CharT, _Traits>& __exp, bool __invert, __node<_CharT>* __s) |
| 2881 | : base(__s), __exp_(__exp), __invert_(__invert) {} |
| 2882 | |
| 2883 | virtual void __exec(__state&) const; |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2884 | }; |
| 2885 | |
| 2886 | template <class _CharT, class _Traits> |
| 2887 | void |
| 2888 | __lookahead<_CharT, _Traits>::__exec(__state& __s) const |
| 2889 | { |
| 2890 | match_results<const _CharT*> __m; |
| 2891 | __m.__init(1 + __exp_.mark_count(), __s.__current_, __s.__last_); |
| 2892 | bool __matched = __exp_.__match_at_start_ecma(__s.__current_, __s.__last_, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2893 | __m, |
| 2894 | __s.__flags_ | regex_constants::match_continuous, |
| 2895 | true); |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2896 | if (__matched != __invert_) |
| 2897 | { |
| 2898 | __s.__do_ = __state::__accept_but_not_consume; |
| 2899 | __s.__node_ = this->first(); |
| 2900 | } |
| 2901 | else |
| 2902 | { |
| 2903 | __s.__do_ = __state::__reject; |
| 2904 | __s.__node_ = nullptr; |
| 2905 | } |
| 2906 | } |
| 2907 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2908 | template <class _CharT, class _Traits> |
| 2909 | template <class _ForwardIterator> |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2910 | _ForwardIterator |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2911 | basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first, |
| 2912 | _ForwardIterator __last) |
| 2913 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2914 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2915 | unique_ptr<__node> __h(new __end_state<_CharT>); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2916 | __start_.reset(new __empty_state<_CharT>(__h.get())); |
| 2917 | __h.release(); |
| 2918 | __end_ = __start_.get(); |
| 2919 | } |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 2920 | switch (__flags_ & 0x1F0) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2921 | { |
| 2922 | case ECMAScript: |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2923 | __first = __parse_ecma_exp(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2924 | break; |
| 2925 | case basic: |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2926 | __first = __parse_basic_reg_exp(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2927 | break; |
| 2928 | case extended: |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2929 | case awk: |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2930 | __first = __parse_extended_reg_exp(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2931 | break; |
| 2932 | case grep: |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2933 | __first = __parse_grep(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2934 | break; |
| 2935 | case egrep: |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2936 | __first = __parse_egrep(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2937 | break; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2938 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2939 | default: |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 2940 | throw regex_error(regex_constants::__re_err_grammar); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2941 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2942 | } |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2943 | return __first; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2944 | } |
| 2945 | |
| 2946 | template <class _CharT, class _Traits> |
| 2947 | template <class _ForwardIterator> |
| 2948 | _ForwardIterator |
| 2949 | basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first, |
| 2950 | _ForwardIterator __last) |
| 2951 | { |
| 2952 | if (__first != __last) |
| 2953 | { |
| 2954 | if (*__first == '^') |
| 2955 | { |
| 2956 | __push_l_anchor(); |
| 2957 | ++__first; |
| 2958 | } |
| 2959 | if (__first != __last) |
| 2960 | { |
| 2961 | __first = __parse_RE_expression(__first, __last); |
| 2962 | if (__first != __last) |
| 2963 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2964 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2965 | if (__temp == __last && *__first == '$') |
| 2966 | { |
| 2967 | __push_r_anchor(); |
| 2968 | ++__first; |
| 2969 | } |
| 2970 | } |
| 2971 | } |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2972 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2973 | if (__first != __last) |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 2974 | throw regex_error(regex_constants::__re_err_empty); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2975 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2976 | } |
| 2977 | return __first; |
| 2978 | } |
| 2979 | |
| 2980 | template <class _CharT, class _Traits> |
| 2981 | template <class _ForwardIterator> |
| 2982 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2983 | basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first, |
| 2984 | _ForwardIterator __last) |
| 2985 | { |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 2986 | __owns_one_state<_CharT>* __sa = __end_; |
| 2987 | _ForwardIterator __temp = __parse_ERE_branch(__first, __last); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2988 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 2989 | if (__temp == __first) |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 2990 | throw regex_error(regex_constants::__re_err_empty); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2991 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 2992 | __first = __temp; |
| 2993 | while (__first != __last && *__first == '|') |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2994 | { |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 2995 | __owns_one_state<_CharT>* __sb = __end_; |
| 2996 | __temp = __parse_ERE_branch(++__first, __last); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2997 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2998 | if (__temp == __first) |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 2999 | throw regex_error(regex_constants::__re_err_empty); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3000 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3001 | __push_alternation(__sa, __sb); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3002 | __first = __temp; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3003 | } |
| 3004 | return __first; |
| 3005 | } |
| 3006 | |
| 3007 | template <class _CharT, class _Traits> |
| 3008 | template <class _ForwardIterator> |
| 3009 | _ForwardIterator |
| 3010 | basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first, |
| 3011 | _ForwardIterator __last) |
| 3012 | { |
| 3013 | _ForwardIterator __temp = __parse_ERE_expression(__first, __last); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3014 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3015 | if (__temp == __first) |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 3016 | throw regex_error(regex_constants::__re_err_empty); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3017 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3018 | do |
| 3019 | { |
| 3020 | __first = __temp; |
| 3021 | __temp = __parse_ERE_expression(__first, __last); |
| 3022 | } while (__temp != __first); |
| 3023 | return __first; |
| 3024 | } |
| 3025 | |
| 3026 | template <class _CharT, class _Traits> |
| 3027 | template <class _ForwardIterator> |
| 3028 | _ForwardIterator |
| 3029 | basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first, |
| 3030 | _ForwardIterator __last) |
| 3031 | { |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3032 | __owns_one_state<_CharT>* __e = __end_; |
| 3033 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3034 | _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last); |
| 3035 | if (__temp == __first && __temp != __last) |
| 3036 | { |
| 3037 | switch (*__temp) |
| 3038 | { |
| 3039 | case '^': |
| 3040 | __push_l_anchor(); |
| 3041 | ++__temp; |
| 3042 | break; |
| 3043 | case '$': |
| 3044 | __push_r_anchor(); |
| 3045 | ++__temp; |
| 3046 | break; |
| 3047 | case '(': |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3048 | __push_begin_marked_subexpression(); |
| 3049 | unsigned __temp_count = __marked_count_; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3050 | ++__open_count_; |
| 3051 | __temp = __parse_extended_reg_exp(++__temp, __last); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3052 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3053 | if (__temp == __last || *__temp != ')') |
| 3054 | throw regex_error(regex_constants::error_paren); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3055 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3056 | __push_end_marked_subexpression(__temp_count); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3057 | --__open_count_; |
| 3058 | ++__temp; |
| 3059 | break; |
| 3060 | } |
| 3061 | } |
| 3062 | if (__temp != __first) |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3063 | __temp = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin+1, |
| 3064 | __marked_count_+1); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3065 | __first = __temp; |
| 3066 | return __first; |
| 3067 | } |
| 3068 | |
| 3069 | template <class _CharT, class _Traits> |
| 3070 | template <class _ForwardIterator> |
| 3071 | _ForwardIterator |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3072 | basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first, |
| 3073 | _ForwardIterator __last) |
| 3074 | { |
| 3075 | while (true) |
| 3076 | { |
| 3077 | _ForwardIterator __temp = __parse_simple_RE(__first, __last); |
| 3078 | if (__temp == __first) |
| 3079 | break; |
| 3080 | __first = __temp; |
| 3081 | } |
| 3082 | return __first; |
| 3083 | } |
| 3084 | |
| 3085 | template <class _CharT, class _Traits> |
| 3086 | template <class _ForwardIterator> |
| 3087 | _ForwardIterator |
| 3088 | basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first, |
| 3089 | _ForwardIterator __last) |
| 3090 | { |
| 3091 | if (__first != __last) |
| 3092 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3093 | __owns_one_state<_CharT>* __e = __end_; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3094 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3095 | _ForwardIterator __temp = __parse_nondupl_RE(__first, __last); |
| 3096 | if (__temp != __first) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3097 | __first = __parse_RE_dupl_symbol(__temp, __last, __e, |
| 3098 | __mexp_begin+1, __marked_count_+1); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3099 | } |
| 3100 | return __first; |
| 3101 | } |
| 3102 | |
| 3103 | template <class _CharT, class _Traits> |
| 3104 | template <class _ForwardIterator> |
| 3105 | _ForwardIterator |
| 3106 | basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first, |
| 3107 | _ForwardIterator __last) |
| 3108 | { |
| 3109 | _ForwardIterator __temp = __first; |
| 3110 | __first = __parse_one_char_or_coll_elem_RE(__first, __last); |
| 3111 | if (__temp == __first) |
| 3112 | { |
| 3113 | __temp = __parse_Back_open_paren(__first, __last); |
| 3114 | if (__temp != __first) |
| 3115 | { |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3116 | __push_begin_marked_subexpression(); |
| 3117 | unsigned __temp_count = __marked_count_; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3118 | __first = __parse_RE_expression(__temp, __last); |
| 3119 | __temp = __parse_Back_close_paren(__first, __last); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3120 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3121 | if (__temp == __first) |
| 3122 | throw regex_error(regex_constants::error_paren); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3123 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3124 | __push_end_marked_subexpression(__temp_count); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3125 | __first = __temp; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3126 | } |
| 3127 | else |
| 3128 | __first = __parse_BACKREF(__first, __last); |
| 3129 | } |
| 3130 | return __first; |
| 3131 | } |
| 3132 | |
| 3133 | template <class _CharT, class _Traits> |
| 3134 | template <class _ForwardIterator> |
| 3135 | _ForwardIterator |
| 3136 | basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE( |
| 3137 | _ForwardIterator __first, |
| 3138 | _ForwardIterator __last) |
| 3139 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3140 | _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3141 | if (__temp == __first) |
| 3142 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3143 | __temp = __parse_QUOTED_CHAR(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3144 | if (__temp == __first) |
| 3145 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3146 | if (__temp != __last && *__temp == '.') |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3147 | { |
| 3148 | __push_match_any(); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3149 | ++__temp; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3150 | } |
| 3151 | else |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3152 | __temp = __parse_bracket_expression(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3153 | } |
| 3154 | } |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3155 | __first = __temp; |
| 3156 | return __first; |
| 3157 | } |
| 3158 | |
| 3159 | template <class _CharT, class _Traits> |
| 3160 | template <class _ForwardIterator> |
| 3161 | _ForwardIterator |
| 3162 | basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE( |
| 3163 | _ForwardIterator __first, |
| 3164 | _ForwardIterator __last) |
| 3165 | { |
| 3166 | _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last); |
| 3167 | if (__temp == __first) |
| 3168 | { |
| 3169 | __temp = __parse_QUOTED_CHAR_ERE(__first, __last); |
| 3170 | if (__temp == __first) |
| 3171 | { |
| 3172 | if (__temp != __last && *__temp == '.') |
| 3173 | { |
| 3174 | __push_match_any(); |
| 3175 | ++__temp; |
| 3176 | } |
| 3177 | else |
| 3178 | __temp = __parse_bracket_expression(__first, __last); |
| 3179 | } |
| 3180 | } |
| 3181 | __first = __temp; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3182 | return __first; |
| 3183 | } |
| 3184 | |
| 3185 | template <class _CharT, class _Traits> |
| 3186 | template <class _ForwardIterator> |
| 3187 | _ForwardIterator |
| 3188 | basic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first, |
| 3189 | _ForwardIterator __last) |
| 3190 | { |
| 3191 | if (__first != __last) |
| 3192 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3193 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3194 | if (__temp != __last) |
| 3195 | { |
| 3196 | if (*__first == '\\' && *__temp == '(') |
| 3197 | __first = ++__temp; |
| 3198 | } |
| 3199 | } |
| 3200 | return __first; |
| 3201 | } |
| 3202 | |
| 3203 | template <class _CharT, class _Traits> |
| 3204 | template <class _ForwardIterator> |
| 3205 | _ForwardIterator |
| 3206 | basic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first, |
| 3207 | _ForwardIterator __last) |
| 3208 | { |
| 3209 | if (__first != __last) |
| 3210 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3211 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3212 | if (__temp != __last) |
| 3213 | { |
| 3214 | if (*__first == '\\' && *__temp == ')') |
| 3215 | __first = ++__temp; |
| 3216 | } |
| 3217 | } |
| 3218 | return __first; |
| 3219 | } |
| 3220 | |
| 3221 | template <class _CharT, class _Traits> |
| 3222 | template <class _ForwardIterator> |
| 3223 | _ForwardIterator |
| 3224 | basic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first, |
| 3225 | _ForwardIterator __last) |
| 3226 | { |
| 3227 | if (__first != __last) |
| 3228 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3229 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3230 | if (__temp != __last) |
| 3231 | { |
| 3232 | if (*__first == '\\' && *__temp == '{') |
| 3233 | __first = ++__temp; |
| 3234 | } |
| 3235 | } |
| 3236 | return __first; |
| 3237 | } |
| 3238 | |
| 3239 | template <class _CharT, class _Traits> |
| 3240 | template <class _ForwardIterator> |
| 3241 | _ForwardIterator |
| 3242 | basic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first, |
| 3243 | _ForwardIterator __last) |
| 3244 | { |
| 3245 | if (__first != __last) |
| 3246 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3247 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3248 | if (__temp != __last) |
| 3249 | { |
| 3250 | if (*__first == '\\' && *__temp == '}') |
| 3251 | __first = ++__temp; |
| 3252 | } |
| 3253 | } |
| 3254 | return __first; |
| 3255 | } |
| 3256 | |
| 3257 | template <class _CharT, class _Traits> |
| 3258 | template <class _ForwardIterator> |
| 3259 | _ForwardIterator |
| 3260 | basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first, |
| 3261 | _ForwardIterator __last) |
| 3262 | { |
| 3263 | if (__first != __last) |
| 3264 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3265 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3266 | if (__temp != __last) |
| 3267 | { |
| 3268 | if (*__first == '\\' && '1' <= *__temp && *__temp <= '9') |
| 3269 | { |
| 3270 | __push_back_ref(*__temp - '0'); |
| 3271 | __first = ++__temp; |
| 3272 | } |
| 3273 | } |
| 3274 | } |
| 3275 | return __first; |
| 3276 | } |
| 3277 | |
| 3278 | template <class _CharT, class _Traits> |
| 3279 | template <class _ForwardIterator> |
| 3280 | _ForwardIterator |
| 3281 | basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first, |
| 3282 | _ForwardIterator __last) |
| 3283 | { |
| 3284 | if (__first != __last) |
| 3285 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3286 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3287 | if (__temp == __last && *__first == '$') |
| 3288 | return __first; |
| 3289 | // Not called inside a bracket |
| 3290 | if (*__first == '.' || *__first == '\\' || *__first == '[') |
| 3291 | return __first; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3292 | __push_char(*__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3293 | ++__first; |
| 3294 | } |
| 3295 | return __first; |
| 3296 | } |
| 3297 | |
| 3298 | template <class _CharT, class _Traits> |
| 3299 | template <class _ForwardIterator> |
| 3300 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3301 | basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first, |
| 3302 | _ForwardIterator __last) |
| 3303 | { |
| 3304 | if (__first != __last) |
| 3305 | { |
| 3306 | switch (*__first) |
| 3307 | { |
| 3308 | case '^': |
| 3309 | case '.': |
| 3310 | case '[': |
| 3311 | case '$': |
| 3312 | case '(': |
| 3313 | case '|': |
| 3314 | case '*': |
| 3315 | case '+': |
| 3316 | case '?': |
| 3317 | case '{': |
| 3318 | case '\\': |
| 3319 | break; |
| 3320 | case ')': |
| 3321 | if (__open_count_ == 0) |
| 3322 | { |
| 3323 | __push_char(*__first); |
| 3324 | ++__first; |
| 3325 | } |
| 3326 | break; |
| 3327 | default: |
| 3328 | __push_char(*__first); |
| 3329 | ++__first; |
| 3330 | break; |
| 3331 | } |
| 3332 | } |
| 3333 | return __first; |
| 3334 | } |
| 3335 | |
| 3336 | template <class _CharT, class _Traits> |
| 3337 | template <class _ForwardIterator> |
| 3338 | _ForwardIterator |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3339 | basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first, |
| 3340 | _ForwardIterator __last) |
| 3341 | { |
| 3342 | if (__first != __last) |
| 3343 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3344 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3345 | if (__temp != __last) |
| 3346 | { |
| 3347 | if (*__first == '\\') |
| 3348 | { |
| 3349 | switch (*__temp) |
| 3350 | { |
| 3351 | case '^': |
| 3352 | case '.': |
| 3353 | case '*': |
| 3354 | case '[': |
| 3355 | case '$': |
| 3356 | case '\\': |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3357 | __push_char(*__temp); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3358 | __first = ++__temp; |
| 3359 | break; |
| 3360 | } |
| 3361 | } |
| 3362 | } |
| 3363 | } |
| 3364 | return __first; |
| 3365 | } |
| 3366 | |
| 3367 | template <class _CharT, class _Traits> |
| 3368 | template <class _ForwardIterator> |
| 3369 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3370 | basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first, |
| 3371 | _ForwardIterator __last) |
| 3372 | { |
| 3373 | if (__first != __last) |
| 3374 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3375 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3376 | if (__temp != __last) |
| 3377 | { |
| 3378 | if (*__first == '\\') |
| 3379 | { |
| 3380 | switch (*__temp) |
| 3381 | { |
| 3382 | case '^': |
| 3383 | case '.': |
| 3384 | case '*': |
| 3385 | case '[': |
| 3386 | case '$': |
| 3387 | case '\\': |
| 3388 | case '(': |
| 3389 | case ')': |
| 3390 | case '|': |
| 3391 | case '+': |
| 3392 | case '?': |
| 3393 | case '{': |
| 3394 | __push_char(*__temp); |
| 3395 | __first = ++__temp; |
| 3396 | break; |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3397 | default: |
| 3398 | if ((__flags_ & 0x1F0) == awk) |
| 3399 | __first = __parse_awk_escape(++__first, __last); |
| 3400 | break; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3401 | } |
| 3402 | } |
| 3403 | } |
| 3404 | } |
| 3405 | return __first; |
| 3406 | } |
| 3407 | |
| 3408 | template <class _CharT, class _Traits> |
| 3409 | template <class _ForwardIterator> |
| 3410 | _ForwardIterator |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3411 | basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3412 | _ForwardIterator __last, |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3413 | __owns_one_state<_CharT>* __s, |
| 3414 | unsigned __mexp_begin, |
| 3415 | unsigned __mexp_end) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3416 | { |
| 3417 | if (__first != __last) |
| 3418 | { |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3419 | if (*__first == '*') |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3420 | { |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3421 | __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3422 | ++__first; |
| 3423 | } |
| 3424 | else |
| 3425 | { |
| 3426 | _ForwardIterator __temp = __parse_Back_open_brace(__first, __last); |
| 3427 | if (__temp != __first) |
| 3428 | { |
| 3429 | int __min = 0; |
| 3430 | __first = __temp; |
| 3431 | __temp = __parse_DUP_COUNT(__first, __last, __min); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3432 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3433 | if (__temp == __first) |
| 3434 | throw regex_error(regex_constants::error_badbrace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3435 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3436 | __first = __temp; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3437 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3438 | if (__first == __last) |
| 3439 | throw regex_error(regex_constants::error_brace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3440 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3441 | if (*__first != ',') |
| 3442 | { |
| 3443 | __temp = __parse_Back_close_brace(__first, __last); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3444 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3445 | if (__temp == __first) |
| 3446 | throw regex_error(regex_constants::error_brace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3447 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 3448 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, |
| 3449 | true); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3450 | __first = __temp; |
| 3451 | } |
| 3452 | else |
| 3453 | { |
| 3454 | ++__first; // consume ',' |
| 3455 | int __max = -1; |
| 3456 | __first = __parse_DUP_COUNT(__first, __last, __max); |
| 3457 | __temp = __parse_Back_close_brace(__first, __last); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3458 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3459 | if (__temp == __first) |
| 3460 | throw regex_error(regex_constants::error_brace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3461 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3462 | if (__max == -1) |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3463 | __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3464 | else |
| 3465 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3466 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3467 | if (__max < __min) |
| 3468 | throw regex_error(regex_constants::error_badbrace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3469 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 3470 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, |
| 3471 | true); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3472 | } |
| 3473 | __first = __temp; |
| 3474 | } |
| 3475 | } |
| 3476 | } |
| 3477 | } |
| 3478 | return __first; |
| 3479 | } |
| 3480 | |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3481 | template <class _CharT, class _Traits> |
| 3482 | template <class _ForwardIterator> |
| 3483 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3484 | basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first, |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3485 | _ForwardIterator __last, |
| 3486 | __owns_one_state<_CharT>* __s, |
| 3487 | unsigned __mexp_begin, |
| 3488 | unsigned __mexp_end) |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3489 | { |
| 3490 | if (__first != __last) |
| 3491 | { |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3492 | unsigned __grammar = __flags_ & 0x1F0; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3493 | switch (*__first) |
| 3494 | { |
| 3495 | case '*': |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3496 | ++__first; |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3497 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3498 | { |
| 3499 | ++__first; |
| 3500 | __push_nongreedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
| 3501 | } |
| 3502 | else |
| 3503 | __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3504 | break; |
| 3505 | case '+': |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3506 | ++__first; |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3507 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3508 | { |
| 3509 | ++__first; |
| 3510 | __push_nongreedy_inf_repeat(1, __s, __mexp_begin, __mexp_end); |
| 3511 | } |
| 3512 | else |
| 3513 | __push_greedy_inf_repeat(1, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3514 | break; |
| 3515 | case '?': |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3516 | ++__first; |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3517 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3518 | { |
| 3519 | ++__first; |
| 3520 | __push_loop(0, 1, __s, __mexp_begin, __mexp_end, false); |
| 3521 | } |
| 3522 | else |
| 3523 | __push_loop(0, 1, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3524 | break; |
| 3525 | case '{': |
| 3526 | { |
| 3527 | int __min; |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3528 | _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3529 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3530 | if (__temp == __first) |
| 3531 | throw regex_error(regex_constants::error_badbrace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3532 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3533 | __first = __temp; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3534 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3535 | if (__first == __last) |
| 3536 | throw regex_error(regex_constants::error_brace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3537 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3538 | switch (*__first) |
| 3539 | { |
| 3540 | case '}': |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3541 | ++__first; |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3542 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3543 | { |
| 3544 | ++__first; |
| 3545 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, false); |
| 3546 | } |
| 3547 | else |
| 3548 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3549 | break; |
| 3550 | case ',': |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3551 | ++__first; |
| 3552 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3553 | if (__first == __last) |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3554 | throw regex_error(regex_constants::error_badbrace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3555 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3556 | if (*__first == '}') |
| 3557 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3558 | ++__first; |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3559 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3560 | { |
| 3561 | ++__first; |
| 3562 | __push_nongreedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
| 3563 | } |
| 3564 | else |
| 3565 | __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3566 | } |
| 3567 | else |
| 3568 | { |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3569 | int __max = -1; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3570 | __temp = __parse_DUP_COUNT(__first, __last, __max); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3571 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3572 | if (__temp == __first) |
| 3573 | throw regex_error(regex_constants::error_brace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3574 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3575 | __first = __temp; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3576 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3577 | if (__first == __last || *__first != '}') |
| 3578 | throw regex_error(regex_constants::error_brace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3579 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3580 | ++__first; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3581 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3582 | if (__max < __min) |
| 3583 | throw regex_error(regex_constants::error_badbrace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3584 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3585 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3586 | { |
| 3587 | ++__first; |
| 3588 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, false); |
| 3589 | } |
| 3590 | else |
| 3591 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3592 | } |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3593 | break; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3594 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3595 | default: |
| 3596 | throw regex_error(regex_constants::error_badbrace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3597 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3598 | } |
| 3599 | } |
| 3600 | break; |
| 3601 | } |
| 3602 | } |
| 3603 | return __first; |
| 3604 | } |
| 3605 | |
| 3606 | template <class _CharT, class _Traits> |
| 3607 | template <class _ForwardIterator> |
| 3608 | _ForwardIterator |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3609 | basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first, |
| 3610 | _ForwardIterator __last) |
| 3611 | { |
| 3612 | if (__first != __last && *__first == '[') |
| 3613 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3614 | ++__first; |
| 3615 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3616 | if (__first == __last) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3617 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3618 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3619 | bool __negate = false; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3620 | if (*__first == '^') |
| 3621 | { |
| 3622 | ++__first; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3623 | __negate = true; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3624 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3625 | __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate); |
| 3626 | // __ml owned by *this |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3627 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3628 | if (__first == __last) |
| 3629 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3630 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3631 | if ((__flags_ & 0x1F0) != ECMAScript && *__first == ']') |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3632 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3633 | __ml->__add_char(']'); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3634 | ++__first; |
| 3635 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3636 | __first = __parse_follow_list(__first, __last, __ml); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3637 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3638 | if (__first == __last) |
| 3639 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3640 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3641 | if (*__first == '-') |
| 3642 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3643 | __ml->__add_char('-'); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3644 | ++__first; |
| 3645 | } |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3646 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3647 | if (__first == __last || *__first != ']') |
| 3648 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3649 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3650 | ++__first; |
| 3651 | } |
| 3652 | return __first; |
| 3653 | } |
| 3654 | |
| 3655 | template <class _CharT, class _Traits> |
| 3656 | template <class _ForwardIterator> |
| 3657 | _ForwardIterator |
| 3658 | basic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3659 | _ForwardIterator __last, |
| 3660 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3661 | { |
| 3662 | if (__first != __last) |
| 3663 | { |
| 3664 | while (true) |
| 3665 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3666 | _ForwardIterator __temp = __parse_expression_term(__first, __last, |
| 3667 | __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3668 | if (__temp == __first) |
| 3669 | break; |
| 3670 | __first = __temp; |
| 3671 | } |
| 3672 | } |
| 3673 | return __first; |
| 3674 | } |
| 3675 | |
| 3676 | template <class _CharT, class _Traits> |
| 3677 | template <class _ForwardIterator> |
| 3678 | _ForwardIterator |
| 3679 | basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3680 | _ForwardIterator __last, |
| 3681 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3682 | { |
| 3683 | if (__first != __last && *__first != ']') |
| 3684 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3685 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3686 | basic_string<_CharT> __start_range; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3687 | if (__temp != __last && *__first == '[') |
| 3688 | { |
| 3689 | if (*__temp == '=') |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3690 | return __parse_equivalence_class(++__temp, __last, __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3691 | else if (*__temp == ':') |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3692 | return __parse_character_class(++__temp, __last, __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3693 | else if (*__temp == '.') |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3694 | __first = __parse_collating_symbol(++__temp, __last, __start_range); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3695 | } |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3696 | unsigned __grammar = __flags_ & 0x1F0; |
| 3697 | if (__start_range.empty()) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3698 | { |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3699 | if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') |
| 3700 | { |
| 3701 | if (__grammar == ECMAScript) |
| 3702 | __first = __parse_class_escape(++__first, __last, __start_range, __ml); |
| 3703 | else |
| 3704 | __first = __parse_awk_escape(++__first, __last, &__start_range); |
| 3705 | } |
| 3706 | else |
| 3707 | { |
| 3708 | __start_range = *__first; |
| 3709 | ++__first; |
| 3710 | } |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3711 | } |
| 3712 | if (__first != __last && *__first != ']') |
| 3713 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3714 | __temp = _VSTD::next(__first); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3715 | if (__temp != __last && *__first == '-' && *__temp != ']') |
| 3716 | { |
| 3717 | // parse a range |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3718 | basic_string<_CharT> __end_range; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3719 | __first = __temp; |
| 3720 | ++__temp; |
| 3721 | if (__temp != __last && *__first == '[' && *__temp == '.') |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3722 | __first = __parse_collating_symbol(++__temp, __last, __end_range); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3723 | else |
| 3724 | { |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3725 | if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') |
| 3726 | { |
| 3727 | if (__grammar == ECMAScript) |
| 3728 | __first = __parse_class_escape(++__first, __last, |
| 3729 | __end_range, __ml); |
| 3730 | else |
| 3731 | __first = __parse_awk_escape(++__first, __last, |
| 3732 | &__end_range); |
| 3733 | } |
| 3734 | else |
| 3735 | { |
| 3736 | __end_range = *__first; |
| 3737 | ++__first; |
| 3738 | } |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3739 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3740 | __ml->__add_range(_VSTD::move(__start_range), _VSTD::move(__end_range)); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3741 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3742 | else |
| 3743 | { |
| 3744 | if (__start_range.size() == 1) |
| 3745 | __ml->__add_char(__start_range[0]); |
| 3746 | else |
| 3747 | __ml->__add_digraph(__start_range[0], __start_range[1]); |
| 3748 | } |
| 3749 | } |
| 3750 | else |
| 3751 | { |
| 3752 | if (__start_range.size() == 1) |
| 3753 | __ml->__add_char(__start_range[0]); |
| 3754 | else |
| 3755 | __ml->__add_digraph(__start_range[0], __start_range[1]); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3756 | } |
| 3757 | } |
| 3758 | return __first; |
| 3759 | } |
| 3760 | |
| 3761 | template <class _CharT, class _Traits> |
| 3762 | template <class _ForwardIterator> |
| 3763 | _ForwardIterator |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3764 | basic_regex<_CharT, _Traits>::__parse_class_escape(_ForwardIterator __first, |
| 3765 | _ForwardIterator __last, |
| 3766 | basic_string<_CharT>& __str, |
| 3767 | __bracket_expression<_CharT, _Traits>* __ml) |
| 3768 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3769 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3770 | if (__first == __last) |
| 3771 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3772 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3773 | switch (*__first) |
| 3774 | { |
| 3775 | case 0: |
| 3776 | __str = *__first; |
| 3777 | return ++__first; |
| 3778 | case 'b': |
| 3779 | __str = _CharT(8); |
| 3780 | return ++__first; |
| 3781 | case 'd': |
| 3782 | __ml->__add_class(ctype_base::digit); |
| 3783 | return ++__first; |
| 3784 | case 'D': |
| 3785 | __ml->__add_neg_class(ctype_base::digit); |
| 3786 | return ++__first; |
| 3787 | case 's': |
| 3788 | __ml->__add_class(ctype_base::space); |
| 3789 | return ++__first; |
| 3790 | case 'S': |
| 3791 | __ml->__add_neg_class(ctype_base::space); |
| 3792 | return ++__first; |
| 3793 | case 'w': |
| 3794 | __ml->__add_class(ctype_base::alnum); |
| 3795 | __ml->__add_char('_'); |
| 3796 | return ++__first; |
| 3797 | case 'W': |
| 3798 | __ml->__add_neg_class(ctype_base::alnum); |
| 3799 | __ml->__add_neg_char('_'); |
| 3800 | return ++__first; |
| 3801 | } |
| 3802 | __first = __parse_character_escape(__first, __last, &__str); |
| 3803 | return __first; |
| 3804 | } |
| 3805 | |
| 3806 | template <class _CharT, class _Traits> |
| 3807 | template <class _ForwardIterator> |
| 3808 | _ForwardIterator |
| 3809 | basic_regex<_CharT, _Traits>::__parse_awk_escape(_ForwardIterator __first, |
| 3810 | _ForwardIterator __last, |
| 3811 | basic_string<_CharT>* __str) |
| 3812 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3813 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3814 | if (__first == __last) |
| 3815 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3816 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3817 | switch (*__first) |
| 3818 | { |
| 3819 | case '\\': |
| 3820 | case '"': |
| 3821 | case '/': |
| 3822 | if (__str) |
| 3823 | *__str = *__first; |
| 3824 | else |
| 3825 | __push_char(*__first); |
| 3826 | return ++__first; |
| 3827 | case 'a': |
| 3828 | if (__str) |
| 3829 | *__str = _CharT(7); |
| 3830 | else |
| 3831 | __push_char(_CharT(7)); |
| 3832 | return ++__first; |
| 3833 | case 'b': |
| 3834 | if (__str) |
| 3835 | *__str = _CharT(8); |
| 3836 | else |
| 3837 | __push_char(_CharT(8)); |
| 3838 | return ++__first; |
| 3839 | case 'f': |
| 3840 | if (__str) |
| 3841 | *__str = _CharT(0xC); |
| 3842 | else |
| 3843 | __push_char(_CharT(0xC)); |
| 3844 | return ++__first; |
| 3845 | case 'n': |
| 3846 | if (__str) |
| 3847 | *__str = _CharT(0xA); |
| 3848 | else |
| 3849 | __push_char(_CharT(0xA)); |
| 3850 | return ++__first; |
| 3851 | case 'r': |
| 3852 | if (__str) |
| 3853 | *__str = _CharT(0xD); |
| 3854 | else |
| 3855 | __push_char(_CharT(0xD)); |
| 3856 | return ++__first; |
| 3857 | case 't': |
| 3858 | if (__str) |
| 3859 | *__str = _CharT(0x9); |
| 3860 | else |
| 3861 | __push_char(_CharT(0x9)); |
| 3862 | return ++__first; |
| 3863 | case 'v': |
| 3864 | if (__str) |
| 3865 | *__str = _CharT(0xB); |
| 3866 | else |
| 3867 | __push_char(_CharT(0xB)); |
| 3868 | return ++__first; |
| 3869 | } |
| 3870 | if ('0' <= *__first && *__first <= '7') |
| 3871 | { |
| 3872 | unsigned __val = *__first - '0'; |
| 3873 | if (++__first != __last && ('0' <= *__first && *__first <= '7')) |
| 3874 | { |
| 3875 | __val = 8 * __val + *__first - '0'; |
| 3876 | if (++__first != __last && ('0' <= *__first && *__first <= '7')) |
| 3877 | __val = 8 * __val + *__first - '0'; |
| 3878 | } |
| 3879 | if (__str) |
| 3880 | *__str = _CharT(__val); |
| 3881 | else |
| 3882 | __push_char(_CharT(__val)); |
| 3883 | } |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3884 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3885 | else |
| 3886 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3887 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3888 | return __first; |
| 3889 | } |
| 3890 | |
| 3891 | template <class _CharT, class _Traits> |
| 3892 | template <class _ForwardIterator> |
| 3893 | _ForwardIterator |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3894 | basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3895 | _ForwardIterator __last, |
| 3896 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3897 | { |
| 3898 | // Found [= |
| 3899 | // This means =] must exist |
| 3900 | value_type _Equal_close[2] = {'=', ']'}; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3901 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Equal_close, |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3902 | _Equal_close+2); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3903 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3904 | if (__temp == __last) |
| 3905 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3906 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3907 | // [__first, __temp) contains all text in [= ... =] |
| 3908 | typedef typename _Traits::string_type string_type; |
| 3909 | string_type __collate_name = |
| 3910 | __traits_.lookup_collatename(__first, __temp); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3911 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3912 | if (__collate_name.empty()) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3913 | throw regex_error(regex_constants::error_collate); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3914 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3915 | string_type __equiv_name = |
| 3916 | __traits_.transform_primary(__collate_name.begin(), |
| 3917 | __collate_name.end()); |
| 3918 | if (!__equiv_name.empty()) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3919 | __ml->__add_equivalence(__equiv_name); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3920 | else |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3921 | { |
| 3922 | switch (__collate_name.size()) |
| 3923 | { |
| 3924 | case 1: |
| 3925 | __ml->__add_char(__collate_name[0]); |
| 3926 | break; |
| 3927 | case 2: |
| 3928 | __ml->__add_digraph(__collate_name[0], __collate_name[1]); |
| 3929 | break; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3930 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3931 | default: |
| 3932 | throw regex_error(regex_constants::error_collate); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3933 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3934 | } |
| 3935 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3936 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3937 | return __first; |
| 3938 | } |
| 3939 | |
| 3940 | template <class _CharT, class _Traits> |
| 3941 | template <class _ForwardIterator> |
| 3942 | _ForwardIterator |
| 3943 | basic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3944 | _ForwardIterator __last, |
| 3945 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3946 | { |
| 3947 | // Found [: |
| 3948 | // This means :] must exist |
| 3949 | value_type _Colon_close[2] = {':', ']'}; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3950 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Colon_close, |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3951 | _Colon_close+2); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3952 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3953 | if (__temp == __last) |
| 3954 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3955 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3956 | // [__first, __temp) contains all text in [: ... :] |
| 3957 | typedef typename _Traits::char_class_type char_class_type; |
| 3958 | char_class_type __class_type = |
| 3959 | __traits_.lookup_classname(__first, __temp, __flags_ & icase); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3960 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3961 | if (__class_type == 0) |
| 3962 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3963 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3964 | __ml->__add_class(__class_type); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3965 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3966 | return __first; |
| 3967 | } |
| 3968 | |
| 3969 | template <class _CharT, class _Traits> |
| 3970 | template <class _ForwardIterator> |
| 3971 | _ForwardIterator |
| 3972 | basic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3973 | _ForwardIterator __last, |
| 3974 | basic_string<_CharT>& __col_sym) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3975 | { |
| 3976 | // Found [. |
| 3977 | // This means .] must exist |
| 3978 | value_type _Dot_close[2] = {'.', ']'}; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3979 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Dot_close, |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3980 | _Dot_close+2); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3981 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3982 | if (__temp == __last) |
| 3983 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3984 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3985 | // [__first, __temp) contains all text in [. ... .] |
| 3986 | typedef typename _Traits::string_type string_type; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3987 | __col_sym = __traits_.lookup_collatename(__first, __temp); |
| 3988 | switch (__col_sym.size()) |
| 3989 | { |
| 3990 | case 1: |
| 3991 | case 2: |
| 3992 | break; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3993 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3994 | default: |
| 3995 | throw regex_error(regex_constants::error_collate); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3996 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3997 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3998 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3999 | return __first; |
| 4000 | } |
| 4001 | |
| 4002 | template <class _CharT, class _Traits> |
| 4003 | template <class _ForwardIterator> |
| 4004 | _ForwardIterator |
| 4005 | basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first, |
| 4006 | _ForwardIterator __last, |
| 4007 | int& __c) |
| 4008 | { |
| 4009 | if (__first != __last && '0' <= *__first && *__first <= '9') |
| 4010 | { |
| 4011 | __c = *__first - '0'; |
| 4012 | for (++__first; __first != __last && '0' <= *__first && *__first <= '9'; |
| 4013 | ++__first) |
| 4014 | { |
| 4015 | __c *= 10; |
| 4016 | __c += *__first - '0'; |
| 4017 | } |
| 4018 | } |
| 4019 | return __first; |
| 4020 | } |
| 4021 | |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4022 | template <class _CharT, class _Traits> |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4023 | template <class _ForwardIterator> |
| 4024 | _ForwardIterator |
| 4025 | basic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first, |
| 4026 | _ForwardIterator __last) |
| 4027 | { |
| 4028 | __owns_one_state<_CharT>* __sa = __end_; |
| 4029 | _ForwardIterator __temp = __parse_alternative(__first, __last); |
| 4030 | if (__temp == __first) |
| 4031 | __push_empty(); |
| 4032 | __first = __temp; |
| 4033 | while (__first != __last && *__first == '|') |
| 4034 | { |
| 4035 | __owns_one_state<_CharT>* __sb = __end_; |
| 4036 | __temp = __parse_alternative(++__first, __last); |
| 4037 | if (__temp == __first) |
| 4038 | __push_empty(); |
| 4039 | __push_alternation(__sa, __sb); |
| 4040 | __first = __temp; |
| 4041 | } |
| 4042 | return __first; |
| 4043 | } |
| 4044 | |
| 4045 | template <class _CharT, class _Traits> |
| 4046 | template <class _ForwardIterator> |
| 4047 | _ForwardIterator |
| 4048 | basic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first, |
| 4049 | _ForwardIterator __last) |
| 4050 | { |
| 4051 | while (true) |
| 4052 | { |
| 4053 | _ForwardIterator __temp = __parse_term(__first, __last); |
| 4054 | if (__temp == __first) |
| 4055 | break; |
| 4056 | __first = __temp; |
| 4057 | } |
| 4058 | return __first; |
| 4059 | } |
| 4060 | |
| 4061 | template <class _CharT, class _Traits> |
| 4062 | template <class _ForwardIterator> |
| 4063 | _ForwardIterator |
| 4064 | basic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first, |
| 4065 | _ForwardIterator __last) |
| 4066 | { |
| 4067 | _ForwardIterator __temp = __parse_assertion(__first, __last); |
| 4068 | if (__temp == __first) |
| 4069 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4070 | __owns_one_state<_CharT>* __e = __end_; |
| 4071 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4072 | __temp = __parse_atom(__first, __last); |
| 4073 | if (__temp != __first) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4074 | __first = __parse_ERE_dupl_symbol(__temp, __last, __e, |
| 4075 | __mexp_begin+1, __marked_count_+1); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4076 | } |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4077 | else |
| 4078 | __first = __temp; |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4079 | return __first; |
| 4080 | } |
| 4081 | |
| 4082 | template <class _CharT, class _Traits> |
| 4083 | template <class _ForwardIterator> |
| 4084 | _ForwardIterator |
| 4085 | basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first, |
| 4086 | _ForwardIterator __last) |
| 4087 | { |
| 4088 | if (__first != __last) |
| 4089 | { |
| 4090 | switch (*__first) |
| 4091 | { |
| 4092 | case '^': |
| 4093 | __push_l_anchor(); |
| 4094 | ++__first; |
| 4095 | break; |
| 4096 | case '$': |
| 4097 | __push_r_anchor(); |
| 4098 | ++__first; |
| 4099 | break; |
| 4100 | case '\\': |
| 4101 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4102 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4103 | if (__temp != __last) |
| 4104 | { |
| 4105 | if (*__temp == 'b') |
| 4106 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4107 | __push_word_boundary(false); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4108 | __first = ++__temp; |
| 4109 | } |
| 4110 | else if (*__temp == 'B') |
| 4111 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4112 | __push_word_boundary(true); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4113 | __first = ++__temp; |
| 4114 | } |
| 4115 | } |
| 4116 | } |
| 4117 | break; |
| 4118 | case '(': |
| 4119 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4120 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4121 | if (__temp != __last && *__temp == '?') |
| 4122 | { |
| 4123 | if (++__temp != __last) |
| 4124 | { |
| 4125 | switch (*__temp) |
| 4126 | { |
| 4127 | case '=': |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4128 | { |
| 4129 | basic_regex __exp; |
| 4130 | __exp.__flags_ = __flags_; |
| 4131 | __temp = __exp.__parse(++__temp, __last); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4132 | __push_lookahead(_VSTD::move(__exp), false); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4133 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4134 | if (__temp == __last || *__temp != ')') |
| 4135 | throw regex_error(regex_constants::error_paren); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4136 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4137 | __first = ++__temp; |
| 4138 | } |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4139 | break; |
| 4140 | case '!': |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4141 | { |
| 4142 | basic_regex __exp; |
| 4143 | __exp.__flags_ = __flags_; |
| 4144 | __temp = __exp.__parse(++__temp, __last); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4145 | __push_lookahead(_VSTD::move(__exp), true); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4146 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4147 | if (__temp == __last || *__temp != ')') |
| 4148 | throw regex_error(regex_constants::error_paren); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4149 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4150 | __first = ++__temp; |
| 4151 | } |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4152 | break; |
| 4153 | } |
| 4154 | } |
| 4155 | } |
| 4156 | } |
| 4157 | break; |
| 4158 | } |
| 4159 | } |
| 4160 | return __first; |
| 4161 | } |
| 4162 | |
| 4163 | template <class _CharT, class _Traits> |
| 4164 | template <class _ForwardIterator> |
| 4165 | _ForwardIterator |
| 4166 | basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first, |
| 4167 | _ForwardIterator __last) |
| 4168 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4169 | if (__first != __last) |
| 4170 | { |
| 4171 | switch (*__first) |
| 4172 | { |
| 4173 | case '.': |
| 4174 | __push_match_any_but_newline(); |
| 4175 | ++__first; |
| 4176 | break; |
| 4177 | case '\\': |
| 4178 | __first = __parse_atom_escape(__first, __last); |
| 4179 | break; |
| 4180 | case '[': |
| 4181 | __first = __parse_bracket_expression(__first, __last); |
| 4182 | break; |
| 4183 | case '(': |
| 4184 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4185 | ++__first; |
| 4186 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4187 | if (__first == __last) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4188 | throw regex_error(regex_constants::error_paren); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4189 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4190 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4191 | if (__temp != __last && *__first == '?' && *__temp == ':') |
| 4192 | { |
| 4193 | ++__open_count_; |
| 4194 | __first = __parse_ecma_exp(++__temp, __last); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4195 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4196 | if (__first == __last || *__first != ')') |
| 4197 | throw regex_error(regex_constants::error_paren); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4198 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4199 | --__open_count_; |
| 4200 | ++__first; |
| 4201 | } |
| 4202 | else |
| 4203 | { |
| 4204 | __push_begin_marked_subexpression(); |
| 4205 | unsigned __temp_count = __marked_count_; |
| 4206 | ++__open_count_; |
| 4207 | __first = __parse_ecma_exp(__first, __last); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4208 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4209 | if (__first == __last || *__first != ')') |
| 4210 | throw regex_error(regex_constants::error_paren); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4211 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4212 | __push_end_marked_subexpression(__temp_count); |
| 4213 | --__open_count_; |
| 4214 | ++__first; |
| 4215 | } |
| 4216 | } |
| 4217 | break; |
| 4218 | default: |
| 4219 | __first = __parse_pattern_character(__first, __last); |
| 4220 | break; |
| 4221 | } |
| 4222 | } |
| 4223 | return __first; |
| 4224 | } |
| 4225 | |
| 4226 | template <class _CharT, class _Traits> |
| 4227 | template <class _ForwardIterator> |
| 4228 | _ForwardIterator |
| 4229 | basic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first, |
| 4230 | _ForwardIterator __last) |
| 4231 | { |
| 4232 | if (__first != __last && *__first == '\\') |
| 4233 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4234 | _ForwardIterator __t1 = _VSTD::next(__first); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4235 | _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last); |
| 4236 | if (__t2 != __t1) |
| 4237 | __first = __t2; |
| 4238 | else |
| 4239 | { |
| 4240 | __t2 = __parse_character_class_escape(__t1, __last); |
| 4241 | if (__t2 != __t1) |
| 4242 | __first = __t2; |
| 4243 | else |
| 4244 | { |
| 4245 | __t2 = __parse_character_escape(__t1, __last); |
| 4246 | if (__t2 != __t1) |
| 4247 | __first = __t2; |
| 4248 | } |
| 4249 | } |
| 4250 | } |
| 4251 | return __first; |
| 4252 | } |
| 4253 | |
| 4254 | template <class _CharT, class _Traits> |
| 4255 | template <class _ForwardIterator> |
| 4256 | _ForwardIterator |
| 4257 | basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first, |
| 4258 | _ForwardIterator __last) |
| 4259 | { |
| 4260 | if (__first != __last) |
| 4261 | { |
| 4262 | if (*__first == '0') |
| 4263 | { |
| 4264 | __push_char(_CharT()); |
| 4265 | ++__first; |
| 4266 | } |
| 4267 | else if ('1' <= *__first && *__first <= '9') |
| 4268 | { |
| 4269 | unsigned __v = *__first - '0'; |
| 4270 | for (++__first; '0' <= *__first && *__first <= '9'; ++__first) |
| 4271 | __v = 10 * __v + *__first - '0'; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4272 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4273 | if (__v > mark_count()) |
| 4274 | throw regex_error(regex_constants::error_backref); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4275 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4276 | __push_back_ref(__v); |
| 4277 | } |
| 4278 | } |
| 4279 | return __first; |
| 4280 | } |
| 4281 | |
| 4282 | template <class _CharT, class _Traits> |
| 4283 | template <class _ForwardIterator> |
| 4284 | _ForwardIterator |
| 4285 | basic_regex<_CharT, _Traits>::__parse_character_class_escape(_ForwardIterator __first, |
| 4286 | _ForwardIterator __last) |
| 4287 | { |
| 4288 | if (__first != __last) |
| 4289 | { |
| 4290 | __bracket_expression<_CharT, _Traits>* __ml; |
| 4291 | switch (*__first) |
| 4292 | { |
| 4293 | case 'd': |
| 4294 | __ml = __start_matching_list(false); |
| 4295 | __ml->__add_class(ctype_base::digit); |
| 4296 | ++__first; |
| 4297 | break; |
| 4298 | case 'D': |
| 4299 | __ml = __start_matching_list(true); |
| 4300 | __ml->__add_class(ctype_base::digit); |
| 4301 | ++__first; |
| 4302 | break; |
| 4303 | case 's': |
| 4304 | __ml = __start_matching_list(false); |
| 4305 | __ml->__add_class(ctype_base::space); |
| 4306 | ++__first; |
| 4307 | break; |
| 4308 | case 'S': |
| 4309 | __ml = __start_matching_list(true); |
| 4310 | __ml->__add_class(ctype_base::space); |
| 4311 | ++__first; |
| 4312 | break; |
| 4313 | case 'w': |
| 4314 | __ml = __start_matching_list(false); |
| 4315 | __ml->__add_class(ctype_base::alnum); |
| 4316 | __ml->__add_char('_'); |
| 4317 | ++__first; |
| 4318 | break; |
| 4319 | case 'W': |
| 4320 | __ml = __start_matching_list(true); |
| 4321 | __ml->__add_class(ctype_base::alnum); |
| 4322 | __ml->__add_char('_'); |
| 4323 | ++__first; |
| 4324 | break; |
| 4325 | } |
| 4326 | } |
| 4327 | return __first; |
| 4328 | } |
| 4329 | |
| 4330 | template <class _CharT, class _Traits> |
| 4331 | template <class _ForwardIterator> |
| 4332 | _ForwardIterator |
| 4333 | basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first, |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4334 | _ForwardIterator __last, |
| 4335 | basic_string<_CharT>* __str) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4336 | { |
| 4337 | if (__first != __last) |
| 4338 | { |
| 4339 | _ForwardIterator __t; |
| 4340 | unsigned __sum = 0; |
| 4341 | int __hd; |
| 4342 | switch (*__first) |
| 4343 | { |
| 4344 | case 'f': |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4345 | if (__str) |
| 4346 | *__str = _CharT(0xC); |
| 4347 | else |
| 4348 | __push_char(_CharT(0xC)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4349 | ++__first; |
| 4350 | break; |
| 4351 | case 'n': |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4352 | if (__str) |
| 4353 | *__str = _CharT(0xA); |
| 4354 | else |
| 4355 | __push_char(_CharT(0xA)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4356 | ++__first; |
| 4357 | break; |
| 4358 | case 'r': |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4359 | if (__str) |
| 4360 | *__str = _CharT(0xD); |
| 4361 | else |
| 4362 | __push_char(_CharT(0xD)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4363 | ++__first; |
| 4364 | break; |
| 4365 | case 't': |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4366 | if (__str) |
| 4367 | *__str = _CharT(0x9); |
| 4368 | else |
| 4369 | __push_char(_CharT(0x9)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4370 | ++__first; |
| 4371 | break; |
| 4372 | case 'v': |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4373 | if (__str) |
| 4374 | *__str = _CharT(0xB); |
| 4375 | else |
| 4376 | __push_char(_CharT(0xB)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4377 | ++__first; |
| 4378 | break; |
| 4379 | case 'c': |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4380 | if ((__t = _VSTD::next(__first)) != __last) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4381 | { |
| 4382 | if ('A' <= *__t <= 'Z' || 'a' <= *__t <= 'z') |
| 4383 | { |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4384 | if (__str) |
| 4385 | *__str = _CharT(*__t % 32); |
| 4386 | else |
| 4387 | __push_char(_CharT(*__t % 32)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4388 | __first = ++__t; |
| 4389 | } |
| 4390 | } |
| 4391 | break; |
| 4392 | case 'u': |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4393 | ++__first; |
| 4394 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4395 | if (__first == __last) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4396 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4397 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4398 | __hd = __traits_.value(*__first, 16); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4399 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4400 | if (__hd == -1) |
| 4401 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4402 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4403 | __sum = 16 * __sum + __hd; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4404 | ++__first; |
| 4405 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4406 | if (__first == __last) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4407 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4408 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4409 | __hd = __traits_.value(*__first, 16); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4410 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4411 | if (__hd == -1) |
| 4412 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4413 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4414 | __sum = 16 * __sum + __hd; |
| 4415 | // drop through |
| 4416 | case 'x': |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4417 | ++__first; |
| 4418 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4419 | if (__first == __last) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4420 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4421 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4422 | __hd = __traits_.value(*__first, 16); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4423 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4424 | if (__hd == -1) |
| 4425 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4426 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4427 | __sum = 16 * __sum + __hd; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4428 | ++__first; |
| 4429 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4430 | if (__first == __last) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4431 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4432 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4433 | __hd = __traits_.value(*__first, 16); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4434 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4435 | if (__hd == -1) |
| 4436 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4437 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4438 | __sum = 16 * __sum + __hd; |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4439 | if (__str) |
| 4440 | *__str = _CharT(__sum); |
| 4441 | else |
| 4442 | __push_char(_CharT(__sum)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4443 | ++__first; |
| 4444 | break; |
| 4445 | default: |
| 4446 | if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum)) |
| 4447 | { |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4448 | if (__str) |
| 4449 | *__str = *__first; |
| 4450 | else |
| 4451 | __push_char(*__first); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4452 | ++__first; |
| 4453 | } |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4454 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4455 | else if (__str) |
| 4456 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4457 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4458 | break; |
| 4459 | } |
| 4460 | } |
| 4461 | return __first; |
| 4462 | } |
| 4463 | |
| 4464 | template <class _CharT, class _Traits> |
| 4465 | template <class _ForwardIterator> |
| 4466 | _ForwardIterator |
| 4467 | basic_regex<_CharT, _Traits>::__parse_pattern_character(_ForwardIterator __first, |
| 4468 | _ForwardIterator __last) |
| 4469 | { |
| 4470 | if (__first != __last) |
| 4471 | { |
| 4472 | switch (*__first) |
| 4473 | { |
| 4474 | case '^': |
| 4475 | case '$': |
| 4476 | case '\\': |
| 4477 | case '.': |
| 4478 | case '*': |
| 4479 | case '+': |
| 4480 | case '?': |
| 4481 | case '(': |
| 4482 | case ')': |
| 4483 | case '[': |
| 4484 | case ']': |
| 4485 | case '{': |
| 4486 | case '}': |
| 4487 | case '|': |
| 4488 | break; |
| 4489 | default: |
| 4490 | __push_char(*__first); |
| 4491 | ++__first; |
| 4492 | break; |
| 4493 | } |
| 4494 | } |
| 4495 | return __first; |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4496 | } |
| 4497 | |
| 4498 | template <class _CharT, class _Traits> |
Howard Hinnant | 856846b | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4499 | template <class _ForwardIterator> |
| 4500 | _ForwardIterator |
| 4501 | basic_regex<_CharT, _Traits>::__parse_grep(_ForwardIterator __first, |
| 4502 | _ForwardIterator __last) |
| 4503 | { |
| 4504 | __owns_one_state<_CharT>* __sa = __end_; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4505 | _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | 856846b | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4506 | if (__t1 != __first) |
| 4507 | __parse_basic_reg_exp(__first, __t1); |
| 4508 | else |
| 4509 | __push_empty(); |
| 4510 | __first = __t1; |
| 4511 | if (__first != __last) |
| 4512 | ++__first; |
| 4513 | while (__first != __last) |
| 4514 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4515 | __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | 856846b | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4516 | __owns_one_state<_CharT>* __sb = __end_; |
| 4517 | if (__t1 != __first) |
| 4518 | __parse_basic_reg_exp(__first, __t1); |
| 4519 | else |
| 4520 | __push_empty(); |
| 4521 | __push_alternation(__sa, __sb); |
| 4522 | __first = __t1; |
| 4523 | if (__first != __last) |
| 4524 | ++__first; |
| 4525 | } |
| 4526 | return __first; |
| 4527 | } |
| 4528 | |
| 4529 | template <class _CharT, class _Traits> |
| 4530 | template <class _ForwardIterator> |
| 4531 | _ForwardIterator |
| 4532 | basic_regex<_CharT, _Traits>::__parse_egrep(_ForwardIterator __first, |
| 4533 | _ForwardIterator __last) |
| 4534 | { |
| 4535 | __owns_one_state<_CharT>* __sa = __end_; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4536 | _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | 856846b | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4537 | if (__t1 != __first) |
| 4538 | __parse_extended_reg_exp(__first, __t1); |
| 4539 | else |
| 4540 | __push_empty(); |
| 4541 | __first = __t1; |
| 4542 | if (__first != __last) |
| 4543 | ++__first; |
| 4544 | while (__first != __last) |
| 4545 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4546 | __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | 856846b | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4547 | __owns_one_state<_CharT>* __sb = __end_; |
| 4548 | if (__t1 != __first) |
| 4549 | __parse_extended_reg_exp(__first, __t1); |
| 4550 | else |
| 4551 | __push_empty(); |
| 4552 | __push_alternation(__sa, __sb); |
| 4553 | __first = __t1; |
| 4554 | if (__first != __last) |
| 4555 | ++__first; |
| 4556 | } |
| 4557 | return __first; |
| 4558 | } |
| 4559 | |
| 4560 | template <class _CharT, class _Traits> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4561 | void |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4562 | basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max, |
| 4563 | __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end, |
| 4564 | bool __greedy) |
| 4565 | { |
| 4566 | unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first())); |
| 4567 | __end_->first() = nullptr; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4568 | unique_ptr<__loop<_CharT> > __e2(new __loop<_CharT>(__loop_count_, |
| 4569 | __s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy, |
| 4570 | __min, __max)); |
| 4571 | __s->first() = nullptr; |
| 4572 | __e1.release(); |
| 4573 | __end_->first() = new __repeat_one_loop<_CharT>(__e2.get()); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4574 | __end_ = __e2->second(); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4575 | __s->first() = __e2.release(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4576 | ++__loop_count_; |
| 4577 | } |
| 4578 | |
| 4579 | template <class _CharT, class _Traits> |
| 4580 | void |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4581 | basic_regex<_CharT, _Traits>::__push_char(value_type __c) |
| 4582 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4583 | if (flags() & icase) |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4584 | __end_->first() = new __match_char_icase<_CharT, _Traits> |
| 4585 | (__traits_, __c, __end_->first()); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4586 | else if (flags() & collate) |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4587 | __end_->first() = new __match_char_collate<_CharT, _Traits> |
| 4588 | (__traits_, __c, __end_->first()); |
| 4589 | else |
| 4590 | __end_->first() = new __match_char<_CharT>(__c, __end_->first()); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 4591 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4592 | } |
| 4593 | |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4594 | template <class _CharT, class _Traits> |
| 4595 | void |
| 4596 | basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression() |
| 4597 | { |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 4598 | if (!(__flags_ & nosubs)) |
| 4599 | { |
| 4600 | __end_->first() = |
| 4601 | new __begin_marked_subexpression<_CharT>(++__marked_count_, |
| 4602 | __end_->first()); |
| 4603 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4604 | } |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4605 | } |
| 4606 | |
| 4607 | template <class _CharT, class _Traits> |
| 4608 | void |
| 4609 | basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub) |
| 4610 | { |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 4611 | if (!(__flags_ & nosubs)) |
| 4612 | { |
| 4613 | __end_->first() = |
| 4614 | new __end_marked_subexpression<_CharT>(__sub, __end_->first()); |
| 4615 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4616 | } |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4617 | } |
| 4618 | |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4619 | template <class _CharT, class _Traits> |
| 4620 | void |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 4621 | basic_regex<_CharT, _Traits>::__push_l_anchor() |
| 4622 | { |
| 4623 | __end_->first() = new __l_anchor<_CharT>(__end_->first()); |
| 4624 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4625 | } |
| 4626 | |
| 4627 | template <class _CharT, class _Traits> |
| 4628 | void |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4629 | basic_regex<_CharT, _Traits>::__push_r_anchor() |
| 4630 | { |
| 4631 | __end_->first() = new __r_anchor<_CharT>(__end_->first()); |
| 4632 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4633 | } |
| 4634 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4635 | template <class _CharT, class _Traits> |
| 4636 | void |
| 4637 | basic_regex<_CharT, _Traits>::__push_match_any() |
| 4638 | { |
| 4639 | __end_->first() = new __match_any<_CharT>(__end_->first()); |
| 4640 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4641 | } |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4642 | |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4643 | template <class _CharT, class _Traits> |
| 4644 | void |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4645 | basic_regex<_CharT, _Traits>::__push_match_any_but_newline() |
| 4646 | { |
| 4647 | __end_->first() = new __match_any_but_newline<_CharT>(__end_->first()); |
| 4648 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4649 | } |
| 4650 | |
| 4651 | template <class _CharT, class _Traits> |
| 4652 | void |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4653 | basic_regex<_CharT, _Traits>::__push_empty() |
| 4654 | { |
| 4655 | __end_->first() = new __empty_state<_CharT>(__end_->first()); |
| 4656 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4657 | } |
| 4658 | |
| 4659 | template <class _CharT, class _Traits> |
| 4660 | void |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4661 | basic_regex<_CharT, _Traits>::__push_word_boundary(bool __invert) |
| 4662 | { |
| 4663 | __end_->first() = new __word_boundary<_CharT, _Traits>(__traits_, __invert, |
| 4664 | __end_->first()); |
| 4665 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4666 | } |
| 4667 | |
| 4668 | template <class _CharT, class _Traits> |
| 4669 | void |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4670 | basic_regex<_CharT, _Traits>::__push_back_ref(int __i) |
| 4671 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4672 | if (flags() & icase) |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4673 | __end_->first() = new __back_ref_icase<_CharT, _Traits> |
| 4674 | (__traits_, __i, __end_->first()); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4675 | else if (flags() & collate) |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4676 | __end_->first() = new __back_ref_collate<_CharT, _Traits> |
| 4677 | (__traits_, __i, __end_->first()); |
| 4678 | else |
| 4679 | __end_->first() = new __back_ref<_CharT>(__i, __end_->first()); |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4680 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4681 | } |
| 4682 | |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4683 | template <class _CharT, class _Traits> |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 4684 | void |
| 4685 | basic_regex<_CharT, _Traits>::__push_alternation(__owns_one_state<_CharT>* __sa, |
| 4686 | __owns_one_state<_CharT>* __ea) |
| 4687 | { |
| 4688 | __sa->first() = new __alternate<_CharT>( |
| 4689 | static_cast<__owns_one_state<_CharT>*>(__sa->first()), |
| 4690 | static_cast<__owns_one_state<_CharT>*>(__ea->first())); |
| 4691 | __ea->first() = nullptr; |
| 4692 | __ea->first() = new __empty_state<_CharT>(__end_->first()); |
| 4693 | __end_->first() = nullptr; |
| 4694 | __end_->first() = new __empty_non_own_state<_CharT>(__ea->first()); |
| 4695 | __end_ = static_cast<__owns_one_state<_CharT>*>(__ea->first()); |
| 4696 | } |
| 4697 | |
| 4698 | template <class _CharT, class _Traits> |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4699 | __bracket_expression<_CharT, _Traits>* |
| 4700 | basic_regex<_CharT, _Traits>::__start_matching_list(bool __negate) |
| 4701 | { |
| 4702 | __bracket_expression<_CharT, _Traits>* __r = |
| 4703 | new __bracket_expression<_CharT, _Traits>(__traits_, __end_->first(), |
| 4704 | __negate, __flags_ & icase, |
| 4705 | __flags_ & collate); |
| 4706 | __end_->first() = __r; |
| 4707 | __end_ = __r; |
| 4708 | return __r; |
| 4709 | } |
| 4710 | |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4711 | template <class _CharT, class _Traits> |
| 4712 | void |
| 4713 | basic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp, |
| 4714 | bool __invert) |
| 4715 | { |
| 4716 | __end_->first() = new __lookahead<_CharT, _Traits>(__exp, __invert, |
| 4717 | __end_->first()); |
| 4718 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4719 | } |
| 4720 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 4721 | typedef basic_regex<char> regex; |
| 4722 | typedef basic_regex<wchar_t> wregex; |
| 4723 | |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4724 | // sub_match |
| 4725 | |
| 4726 | template <class _BidirectionalIterator> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4727 | class _LIBCPP_VISIBLE sub_match |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4728 | : public pair<_BidirectionalIterator, _BidirectionalIterator> |
| 4729 | { |
| 4730 | public: |
| 4731 | typedef _BidirectionalIterator iterator; |
| 4732 | typedef typename iterator_traits<iterator>::value_type value_type; |
| 4733 | typedef typename iterator_traits<iterator>::difference_type difference_type; |
| 4734 | typedef basic_string<value_type> string_type; |
| 4735 | |
| 4736 | bool matched; |
| 4737 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4738 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 4739 | /*constexpr*/ sub_match() : matched() {} |
| 4740 | |
| 4741 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4742 | difference_type length() const |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4743 | {return matched ? _VSTD::distance(this->first, this->second) : 0;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4744 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4745 | string_type str() const |
| 4746 | {return matched ? string_type(this->first, this->second) : string_type();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4747 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4748 | operator string_type() const |
| 4749 | {return str();} |
| 4750 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4751 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4752 | int compare(const sub_match& __s) const |
| 4753 | {return str().compare(__s.str());} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4754 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4755 | int compare(const string_type& __s) const |
| 4756 | {return str().compare(__s);} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4757 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4758 | int compare(const value_type* __s) const |
| 4759 | {return str().compare(__s);} |
| 4760 | }; |
| 4761 | |
| 4762 | typedef sub_match<const char*> csub_match; |
| 4763 | typedef sub_match<const wchar_t*> wcsub_match; |
| 4764 | typedef sub_match<string::const_iterator> ssub_match; |
| 4765 | typedef sub_match<wstring::const_iterator> wssub_match; |
| 4766 | |
| 4767 | template <class _BiIter> |
| 4768 | inline _LIBCPP_INLINE_VISIBILITY |
| 4769 | bool |
| 4770 | operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4771 | { |
| 4772 | return __x.compare(__y) == 0; |
| 4773 | } |
| 4774 | |
| 4775 | template <class _BiIter> |
| 4776 | inline _LIBCPP_INLINE_VISIBILITY |
| 4777 | bool |
| 4778 | operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4779 | { |
| 4780 | return !(__x == __y); |
| 4781 | } |
| 4782 | |
| 4783 | template <class _BiIter> |
| 4784 | inline _LIBCPP_INLINE_VISIBILITY |
| 4785 | bool |
| 4786 | operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4787 | { |
| 4788 | return __x.compare(__y) < 0; |
| 4789 | } |
| 4790 | |
| 4791 | template <class _BiIter> |
| 4792 | inline _LIBCPP_INLINE_VISIBILITY |
| 4793 | bool |
| 4794 | operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4795 | { |
| 4796 | return !(__y < __x); |
| 4797 | } |
| 4798 | |
| 4799 | template <class _BiIter> |
| 4800 | inline _LIBCPP_INLINE_VISIBILITY |
| 4801 | bool |
| 4802 | operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4803 | { |
| 4804 | return !(__x < __y); |
| 4805 | } |
| 4806 | |
| 4807 | template <class _BiIter> |
| 4808 | inline _LIBCPP_INLINE_VISIBILITY |
| 4809 | bool |
| 4810 | operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4811 | { |
| 4812 | return __y < __x; |
| 4813 | } |
| 4814 | |
| 4815 | template <class _BiIter, class _ST, class _SA> |
| 4816 | inline _LIBCPP_INLINE_VISIBILITY |
| 4817 | bool |
| 4818 | operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4819 | const sub_match<_BiIter>& __y) |
| 4820 | { |
| 4821 | return __y.compare(__x.c_str()) == 0; |
| 4822 | } |
| 4823 | |
| 4824 | template <class _BiIter, class _ST, class _SA> |
| 4825 | inline _LIBCPP_INLINE_VISIBILITY |
| 4826 | bool |
| 4827 | operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4828 | const sub_match<_BiIter>& __y) |
| 4829 | { |
| 4830 | return !(__x == __y); |
| 4831 | } |
| 4832 | |
| 4833 | template <class _BiIter, class _ST, class _SA> |
| 4834 | inline _LIBCPP_INLINE_VISIBILITY |
| 4835 | bool |
| 4836 | operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4837 | const sub_match<_BiIter>& __y) |
| 4838 | { |
| 4839 | return __y.compare(__x.c_str()) > 0; |
| 4840 | } |
| 4841 | |
| 4842 | template <class _BiIter, class _ST, class _SA> |
| 4843 | inline _LIBCPP_INLINE_VISIBILITY |
| 4844 | bool |
| 4845 | operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4846 | const sub_match<_BiIter>& __y) |
| 4847 | { |
| 4848 | return __y < __x; |
| 4849 | } |
| 4850 | |
| 4851 | template <class _BiIter, class _ST, class _SA> |
| 4852 | inline _LIBCPP_INLINE_VISIBILITY |
| 4853 | bool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4854 | const sub_match<_BiIter>& __y) |
| 4855 | { |
| 4856 | return !(__x < __y); |
| 4857 | } |
| 4858 | |
| 4859 | template <class _BiIter, class _ST, class _SA> |
| 4860 | inline _LIBCPP_INLINE_VISIBILITY |
| 4861 | bool |
| 4862 | operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4863 | const sub_match<_BiIter>& __y) |
| 4864 | { |
| 4865 | return !(__y < __x); |
| 4866 | } |
| 4867 | |
| 4868 | template <class _BiIter, class _ST, class _SA> |
| 4869 | inline _LIBCPP_INLINE_VISIBILITY |
| 4870 | bool |
| 4871 | operator==(const sub_match<_BiIter>& __x, |
| 4872 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4873 | { |
| 4874 | return __x.compare(__y.c_str()) == 0; |
| 4875 | } |
| 4876 | |
| 4877 | template <class _BiIter, class _ST, class _SA> |
| 4878 | inline _LIBCPP_INLINE_VISIBILITY |
| 4879 | bool |
| 4880 | operator!=(const sub_match<_BiIter>& __x, |
| 4881 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4882 | { |
| 4883 | return !(__x == __y); |
| 4884 | } |
| 4885 | |
| 4886 | template <class _BiIter, class _ST, class _SA> |
| 4887 | inline _LIBCPP_INLINE_VISIBILITY |
| 4888 | bool |
| 4889 | operator<(const sub_match<_BiIter>& __x, |
| 4890 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4891 | { |
| 4892 | return __x.compare(__y.c_str()) < 0; |
| 4893 | } |
| 4894 | |
| 4895 | template <class _BiIter, class _ST, class _SA> |
| 4896 | inline _LIBCPP_INLINE_VISIBILITY |
| 4897 | bool operator>(const sub_match<_BiIter>& __x, |
| 4898 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4899 | { |
| 4900 | return __y < __x; |
| 4901 | } |
| 4902 | |
| 4903 | template <class _BiIter, class _ST, class _SA> |
| 4904 | inline _LIBCPP_INLINE_VISIBILITY |
| 4905 | bool |
| 4906 | operator>=(const sub_match<_BiIter>& __x, |
| 4907 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4908 | { |
| 4909 | return !(__x < __y); |
| 4910 | } |
| 4911 | |
| 4912 | template <class _BiIter, class _ST, class _SA> |
| 4913 | inline _LIBCPP_INLINE_VISIBILITY |
| 4914 | bool |
| 4915 | operator<=(const sub_match<_BiIter>& __x, |
| 4916 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4917 | { |
| 4918 | return !(__y < __x); |
| 4919 | } |
| 4920 | |
| 4921 | template <class _BiIter> |
| 4922 | inline _LIBCPP_INLINE_VISIBILITY |
| 4923 | bool |
| 4924 | operator==(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4925 | const sub_match<_BiIter>& __y) |
| 4926 | { |
| 4927 | return __y.compare(__x) == 0; |
| 4928 | } |
| 4929 | |
| 4930 | template <class _BiIter> |
| 4931 | inline _LIBCPP_INLINE_VISIBILITY |
| 4932 | bool |
| 4933 | operator!=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4934 | const sub_match<_BiIter>& __y) |
| 4935 | { |
| 4936 | return !(__x == __y); |
| 4937 | } |
| 4938 | |
| 4939 | template <class _BiIter> |
| 4940 | inline _LIBCPP_INLINE_VISIBILITY |
| 4941 | bool |
| 4942 | operator<(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4943 | const sub_match<_BiIter>& __y) |
| 4944 | { |
| 4945 | return __y.compare(__x) > 0; |
| 4946 | } |
| 4947 | |
| 4948 | template <class _BiIter> |
| 4949 | inline _LIBCPP_INLINE_VISIBILITY |
| 4950 | bool |
| 4951 | operator>(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4952 | const sub_match<_BiIter>& __y) |
| 4953 | { |
| 4954 | return __y < __x; |
| 4955 | } |
| 4956 | |
| 4957 | template <class _BiIter> |
| 4958 | inline _LIBCPP_INLINE_VISIBILITY |
| 4959 | bool |
| 4960 | operator>=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4961 | const sub_match<_BiIter>& __y) |
| 4962 | { |
| 4963 | return !(__x < __y); |
| 4964 | } |
| 4965 | |
| 4966 | template <class _BiIter> |
| 4967 | inline _LIBCPP_INLINE_VISIBILITY |
| 4968 | bool |
| 4969 | operator<=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4970 | const sub_match<_BiIter>& __y) |
| 4971 | { |
| 4972 | return !(__y < __x); |
| 4973 | } |
| 4974 | |
| 4975 | template <class _BiIter> |
| 4976 | inline _LIBCPP_INLINE_VISIBILITY |
| 4977 | bool |
| 4978 | operator==(const sub_match<_BiIter>& __x, |
| 4979 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 4980 | { |
| 4981 | return __x.compare(__y) == 0; |
| 4982 | } |
| 4983 | |
| 4984 | template <class _BiIter> |
| 4985 | inline _LIBCPP_INLINE_VISIBILITY |
| 4986 | bool |
| 4987 | operator!=(const sub_match<_BiIter>& __x, |
| 4988 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 4989 | { |
| 4990 | return !(__x == __y); |
| 4991 | } |
| 4992 | |
| 4993 | template <class _BiIter> |
| 4994 | inline _LIBCPP_INLINE_VISIBILITY |
| 4995 | bool |
| 4996 | operator<(const sub_match<_BiIter>& __x, |
| 4997 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 4998 | { |
| 4999 | return __x.compare(__y) < 0; |
| 5000 | } |
| 5001 | |
| 5002 | template <class _BiIter> |
| 5003 | inline _LIBCPP_INLINE_VISIBILITY |
| 5004 | bool |
| 5005 | operator>(const sub_match<_BiIter>& __x, |
| 5006 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5007 | { |
| 5008 | return __y < __x; |
| 5009 | } |
| 5010 | |
| 5011 | template <class _BiIter> |
| 5012 | inline _LIBCPP_INLINE_VISIBILITY |
| 5013 | bool |
| 5014 | operator>=(const sub_match<_BiIter>& __x, |
| 5015 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5016 | { |
| 5017 | return !(__x < __y); |
| 5018 | } |
| 5019 | |
| 5020 | template <class _BiIter> |
| 5021 | inline _LIBCPP_INLINE_VISIBILITY |
| 5022 | bool |
| 5023 | operator<=(const sub_match<_BiIter>& __x, |
| 5024 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5025 | { |
| 5026 | return !(__y < __x); |
| 5027 | } |
| 5028 | |
| 5029 | template <class _BiIter> |
| 5030 | inline _LIBCPP_INLINE_VISIBILITY |
| 5031 | bool |
| 5032 | operator==(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5033 | const sub_match<_BiIter>& __y) |
| 5034 | { |
| 5035 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5036 | return __y.compare(string_type(1, __x)) == 0; |
| 5037 | } |
| 5038 | |
| 5039 | template <class _BiIter> |
| 5040 | inline _LIBCPP_INLINE_VISIBILITY |
| 5041 | bool |
| 5042 | operator!=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5043 | const sub_match<_BiIter>& __y) |
| 5044 | { |
| 5045 | return !(__x == __y); |
| 5046 | } |
| 5047 | |
| 5048 | template <class _BiIter> |
| 5049 | inline _LIBCPP_INLINE_VISIBILITY |
| 5050 | bool |
| 5051 | operator<(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5052 | const sub_match<_BiIter>& __y) |
| 5053 | { |
| 5054 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5055 | return __y.compare(string_type(1, __x)) > 0; |
| 5056 | } |
| 5057 | |
| 5058 | template <class _BiIter> |
| 5059 | inline _LIBCPP_INLINE_VISIBILITY |
| 5060 | bool |
| 5061 | operator>(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5062 | const sub_match<_BiIter>& __y) |
| 5063 | { |
| 5064 | return __y < __x; |
| 5065 | } |
| 5066 | |
| 5067 | template <class _BiIter> |
| 5068 | inline _LIBCPP_INLINE_VISIBILITY |
| 5069 | bool |
| 5070 | operator>=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5071 | const sub_match<_BiIter>& __y) |
| 5072 | { |
| 5073 | return !(__x < __y); |
| 5074 | } |
| 5075 | |
| 5076 | template <class _BiIter> |
| 5077 | inline _LIBCPP_INLINE_VISIBILITY |
| 5078 | bool |
| 5079 | operator<=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5080 | const sub_match<_BiIter>& __y) |
| 5081 | { |
| 5082 | return !(__y < __x); |
| 5083 | } |
| 5084 | |
| 5085 | template <class _BiIter> |
| 5086 | inline _LIBCPP_INLINE_VISIBILITY |
| 5087 | bool |
| 5088 | operator==(const sub_match<_BiIter>& __x, |
| 5089 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5090 | { |
| 5091 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5092 | return __x.compare(string_type(1, __y)) == 0; |
| 5093 | } |
| 5094 | |
| 5095 | template <class _BiIter> |
| 5096 | inline _LIBCPP_INLINE_VISIBILITY |
| 5097 | bool |
| 5098 | operator!=(const sub_match<_BiIter>& __x, |
| 5099 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5100 | { |
| 5101 | return !(__x == __y); |
| 5102 | } |
| 5103 | |
| 5104 | template <class _BiIter> |
| 5105 | inline _LIBCPP_INLINE_VISIBILITY |
| 5106 | bool |
| 5107 | operator<(const sub_match<_BiIter>& __x, |
| 5108 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5109 | { |
| 5110 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5111 | return __x.compare(string_type(1, __y)) < 0; |
| 5112 | } |
| 5113 | |
| 5114 | template <class _BiIter> |
| 5115 | inline _LIBCPP_INLINE_VISIBILITY |
| 5116 | bool |
| 5117 | operator>(const sub_match<_BiIter>& __x, |
| 5118 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5119 | { |
| 5120 | return __y < __x; |
| 5121 | } |
| 5122 | |
| 5123 | template <class _BiIter> |
| 5124 | inline _LIBCPP_INLINE_VISIBILITY |
| 5125 | bool |
| 5126 | operator>=(const sub_match<_BiIter>& __x, |
| 5127 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5128 | { |
| 5129 | return !(__x < __y); |
| 5130 | } |
| 5131 | |
| 5132 | template <class _BiIter> |
| 5133 | inline _LIBCPP_INLINE_VISIBILITY |
| 5134 | bool |
| 5135 | operator<=(const sub_match<_BiIter>& __x, |
| 5136 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5137 | { |
| 5138 | return !(__y < __x); |
| 5139 | } |
| 5140 | |
| 5141 | template <class _CharT, class _ST, class _BiIter> |
| 5142 | inline _LIBCPP_INLINE_VISIBILITY |
| 5143 | basic_ostream<_CharT, _ST>& |
| 5144 | operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m) |
| 5145 | { |
| 5146 | return __os << __m.str(); |
| 5147 | } |
| 5148 | |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5149 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5150 | class _LIBCPP_VISIBLE match_results |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5151 | { |
| 5152 | public: |
| 5153 | typedef _Allocator allocator_type; |
| 5154 | typedef sub_match<_BidirectionalIterator> value_type; |
| 5155 | private: |
| 5156 | typedef vector<value_type, allocator_type> __container_type; |
| 5157 | |
| 5158 | __container_type __matches_; |
| 5159 | value_type __unmatched_; |
| 5160 | value_type __prefix_; |
| 5161 | value_type __suffix_; |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5162 | bool __ready_; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5163 | public: |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5164 | _BidirectionalIterator __position_start_; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5165 | typedef const value_type& const_reference; |
| 5166 | typedef const_reference reference; |
| 5167 | typedef typename __container_type::const_iterator const_iterator; |
| 5168 | typedef const_iterator iterator; |
| 5169 | typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; |
| 5170 | typedef typename allocator_traits<allocator_type>::size_type size_type; |
| 5171 | typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type; |
| 5172 | typedef basic_string<char_type> string_type; |
| 5173 | |
| 5174 | // construct/copy/destroy: |
| 5175 | explicit match_results(const allocator_type& __a = allocator_type()); |
| 5176 | // match_results(const match_results&) = default; |
| 5177 | // match_results& operator=(const match_results&) = default; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5178 | // match_results(match_results&& __m) = default; |
| 5179 | // match_results& operator=(match_results&& __m) = default; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5180 | // ~match_results() = default; |
| 5181 | |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5182 | _LIBCPP_INLINE_VISIBILITY |
| 5183 | bool ready() const {return __ready_;} |
| 5184 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5185 | // size: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5186 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5187 | size_type size() const {return __matches_.size();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5188 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5189 | size_type max_size() const {return __matches_.max_size();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5190 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5191 | bool empty() const {return size() == 0;} |
| 5192 | |
| 5193 | // element access: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5194 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5195 | difference_type length(size_type __sub = 0) const |
| 5196 | {return (*this)[__sub].length();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5197 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5198 | difference_type position(size_type __sub = 0) const |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5199 | {return _VSTD::distance(__position_start_, (*this)[__sub].first);} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5200 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5201 | string_type str(size_type __sub = 0) const |
| 5202 | {return (*this)[__sub].str();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5203 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5204 | const_reference operator[](size_type __n) const |
| 5205 | {return __n < __matches_.size() ? __matches_[__n] : __unmatched_;} |
| 5206 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5207 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5208 | const_reference prefix() const {return __prefix_;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5209 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5210 | const_reference suffix() const {return __suffix_;} |
| 5211 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5212 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c6fe8ca | 2011-10-08 14:36:16 +0000 | [diff] [blame] | 5213 | const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5214 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5215 | const_iterator end() const {return __matches_.end();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5216 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c6fe8ca | 2011-10-08 14:36:16 +0000 | [diff] [blame] | 5217 | const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5218 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5219 | const_iterator cend() const {return __matches_.end();} |
| 5220 | |
| 5221 | // format: |
| 5222 | template <class _OutputIter> |
| 5223 | _OutputIter |
| 5224 | format(_OutputIter __out, const char_type* __fmt_first, |
| 5225 | const char_type* __fmt_last, |
| 5226 | regex_constants::match_flag_type __flags = regex_constants::format_default) const; |
| 5227 | template <class _OutputIter, class _ST, class _SA> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5228 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5229 | _OutputIter |
| 5230 | format(_OutputIter __out, const basic_string<char_type, _ST, _SA>& __fmt, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5231 | regex_constants::match_flag_type __flags = regex_constants::format_default) const |
| 5232 | {return format(__out, __fmt.data(), __fmt.data() + __fmt.size(), __flags);} |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5233 | template <class _ST, class _SA> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5234 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5235 | basic_string<char_type, _ST, _SA> |
| 5236 | format(const basic_string<char_type, _ST, _SA>& __fmt, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5237 | regex_constants::match_flag_type __flags = regex_constants::format_default) const |
| 5238 | { |
| 5239 | basic_string<char_type, _ST, _SA> __r; |
| 5240 | format(back_inserter(__r), __fmt.data(), __fmt.data() + __fmt.size(), |
| 5241 | __flags); |
| 5242 | return __r; |
| 5243 | } |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5244 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5245 | string_type |
| 5246 | format(const char_type* __fmt, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5247 | regex_constants::match_flag_type __flags = regex_constants::format_default) const |
| 5248 | { |
| 5249 | string_type __r; |
| 5250 | format(back_inserter(__r), __fmt, |
| 5251 | __fmt + char_traits<char_type>::length(__fmt), __flags); |
| 5252 | return __r; |
| 5253 | } |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5254 | |
| 5255 | // allocator: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5256 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5257 | allocator_type get_allocator() const {return __matches_.get_allocator();} |
| 5258 | |
| 5259 | // swap: |
| 5260 | void swap(match_results& __m); |
| 5261 | |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5262 | template <class _B, class _A> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5263 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5264 | void __assign(_BidirectionalIterator __f, _BidirectionalIterator __l, |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5265 | const match_results<_B, _A>& __m, bool __no_update_pos) |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5266 | { |
| 5267 | _B __mf = __m.prefix().first; |
| 5268 | __matches_.resize(__m.size()); |
| 5269 | for (size_type __i = 0; __i < __matches_.size(); ++__i) |
| 5270 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5271 | __matches_[__i].first = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].first)); |
| 5272 | __matches_[__i].second = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].second)); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5273 | __matches_[__i].matched = __m[__i].matched; |
| 5274 | } |
| 5275 | __unmatched_.first = __l; |
| 5276 | __unmatched_.second = __l; |
| 5277 | __unmatched_.matched = false; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5278 | __prefix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().first)); |
| 5279 | __prefix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().second)); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5280 | __prefix_.matched = __m.prefix().matched; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5281 | __suffix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().first)); |
| 5282 | __suffix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().second)); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5283 | __suffix_.matched = __m.suffix().matched; |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5284 | if (!__no_update_pos) |
| 5285 | __position_start_ = __prefix_.first; |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5286 | __ready_ = __m.ready(); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5287 | } |
| 5288 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5289 | private: |
| 5290 | void __init(unsigned __s, |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5291 | _BidirectionalIterator __f, _BidirectionalIterator __l, |
| 5292 | bool __no_update_pos = false); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5293 | |
| 5294 | template <class, class> friend class basic_regex; |
| 5295 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5296 | template <class _B, class _A, class _C, class _T> |
| 5297 | friend |
| 5298 | bool |
| 5299 | regex_match(_B, _B, match_results<_B, _A>&, const basic_regex<_C, _T>&, |
| 5300 | regex_constants::match_flag_type); |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 5301 | |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5302 | template <class _B, class _A> |
| 5303 | friend |
| 5304 | bool |
| 5305 | operator==(const match_results<_B, _A>&, const match_results<_B, _A>&); |
| 5306 | |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 5307 | template <class, class> friend class __lookahead; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5308 | }; |
| 5309 | |
| 5310 | template <class _BidirectionalIterator, class _Allocator> |
| 5311 | match_results<_BidirectionalIterator, _Allocator>::match_results( |
| 5312 | const allocator_type& __a) |
| 5313 | : __matches_(__a), |
| 5314 | __unmatched_(), |
| 5315 | __prefix_(), |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5316 | __suffix_(), |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5317 | __position_start_(), |
| 5318 | __ready_(false) |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5319 | { |
| 5320 | } |
| 5321 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5322 | template <class _BidirectionalIterator, class _Allocator> |
| 5323 | void |
| 5324 | match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s, |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5325 | _BidirectionalIterator __f, _BidirectionalIterator __l, |
| 5326 | bool __no_update_pos) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5327 | { |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5328 | __unmatched_.first = __l; |
| 5329 | __unmatched_.second = __l; |
| 5330 | __unmatched_.matched = false; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5331 | __matches_.assign(__s, __unmatched_); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5332 | __prefix_.first = __f; |
| 5333 | __prefix_.second = __f; |
| 5334 | __prefix_.matched = false; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5335 | __suffix_ = __unmatched_; |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5336 | if (!__no_update_pos) |
| 5337 | __position_start_ = __prefix_.first; |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5338 | __ready_ = true; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5339 | } |
| 5340 | |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5341 | template <class _BidirectionalIterator, class _Allocator> |
| 5342 | template <class _OutputIter> |
| 5343 | _OutputIter |
| 5344 | match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __out, |
| 5345 | const char_type* __fmt_first, const char_type* __fmt_last, |
| 5346 | regex_constants::match_flag_type __flags) const |
| 5347 | { |
| 5348 | if (__flags & regex_constants::format_sed) |
| 5349 | { |
| 5350 | for (; __fmt_first != __fmt_last; ++__fmt_first) |
| 5351 | { |
| 5352 | if (*__fmt_first == '&') |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5353 | __out = _VSTD::copy(__matches_[0].first, __matches_[0].second, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5354 | __out); |
| 5355 | else if (*__fmt_first == '\\' && __fmt_first + 1 != __fmt_last) |
| 5356 | { |
| 5357 | ++__fmt_first; |
| 5358 | if ('0' <= *__fmt_first && *__fmt_first <= '9') |
| 5359 | { |
| 5360 | size_t __i = *__fmt_first - '0'; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5361 | __out = _VSTD::copy(__matches_[__i].first, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5362 | __matches_[__i].second, __out); |
| 5363 | } |
| 5364 | else |
| 5365 | { |
| 5366 | *__out = *__fmt_first; |
| 5367 | ++__out; |
| 5368 | } |
| 5369 | } |
| 5370 | else |
| 5371 | { |
| 5372 | *__out = *__fmt_first; |
| 5373 | ++__out; |
| 5374 | } |
| 5375 | } |
| 5376 | } |
| 5377 | else |
| 5378 | { |
| 5379 | for (; __fmt_first != __fmt_last; ++__fmt_first) |
| 5380 | { |
| 5381 | if (*__fmt_first == '$' && __fmt_first + 1 != __fmt_last) |
| 5382 | { |
| 5383 | switch (__fmt_first[1]) |
| 5384 | { |
| 5385 | case '$': |
| 5386 | *__out = *++__fmt_first; |
| 5387 | ++__out; |
| 5388 | break; |
| 5389 | case '&': |
| 5390 | ++__fmt_first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5391 | __out = _VSTD::copy(__matches_[0].first, __matches_[0].second, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5392 | __out); |
| 5393 | break; |
| 5394 | case '`': |
| 5395 | ++__fmt_first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5396 | __out = _VSTD::copy(__prefix_.first, __prefix_.second, __out); |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5397 | break; |
| 5398 | case '\'': |
| 5399 | ++__fmt_first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5400 | __out = _VSTD::copy(__suffix_.first, __suffix_.second, __out); |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5401 | break; |
| 5402 | default: |
| 5403 | if ('0' <= __fmt_first[1] && __fmt_first[1] <= '9') |
| 5404 | { |
| 5405 | ++__fmt_first; |
| 5406 | size_t __i = *__fmt_first - '0'; |
| 5407 | if (__fmt_first + 1 != __fmt_last && |
| 5408 | '0' <= __fmt_first[1] && __fmt_first[1] <= '9') |
| 5409 | { |
| 5410 | ++__fmt_first; |
| 5411 | __i = 10 * __i + *__fmt_first - '0'; |
| 5412 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5413 | __out = _VSTD::copy(__matches_[__i].first, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5414 | __matches_[__i].second, __out); |
| 5415 | } |
| 5416 | else |
| 5417 | { |
| 5418 | *__out = *__fmt_first; |
| 5419 | ++__out; |
| 5420 | } |
| 5421 | break; |
| 5422 | } |
| 5423 | } |
| 5424 | else |
| 5425 | { |
| 5426 | *__out = *__fmt_first; |
| 5427 | ++__out; |
| 5428 | } |
| 5429 | } |
| 5430 | } |
| 5431 | return __out; |
| 5432 | } |
| 5433 | |
| 5434 | template <class _BidirectionalIterator, class _Allocator> |
| 5435 | void |
| 5436 | match_results<_BidirectionalIterator, _Allocator>::swap(match_results& __m) |
| 5437 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5438 | using _VSTD::swap; |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5439 | swap(__matches_, __m.__matches_); |
| 5440 | swap(__unmatched_, __m.__unmatched_); |
| 5441 | swap(__prefix_, __m.__prefix_); |
| 5442 | swap(__suffix_, __m.__suffix_); |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5443 | swap(__position_start_, __m.__position_start_); |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5444 | swap(__ready_, __m.__ready_); |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5445 | } |
| 5446 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5447 | typedef match_results<const char*> cmatch; |
| 5448 | typedef match_results<const wchar_t*> wcmatch; |
| 5449 | typedef match_results<string::const_iterator> smatch; |
| 5450 | typedef match_results<wstring::const_iterator> wsmatch; |
| 5451 | |
| 5452 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5453 | bool |
| 5454 | operator==(const match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5455 | const match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5456 | { |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5457 | if (__x.__ready_ != __y.__ready_) |
| 5458 | return false; |
| 5459 | if (!__x.__ready_) |
| 5460 | return true; |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5461 | return __x.__matches_ == __y.__matches_ && |
| 5462 | __x.__prefix_ == __y.__prefix_ && |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5463 | __x.__suffix_ == __y.__suffix_; |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5464 | } |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5465 | |
| 5466 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5467 | inline _LIBCPP_INLINE_VISIBILITY |
| 5468 | bool |
| 5469 | operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5470 | const match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5471 | { |
| 5472 | return !(__x == __y); |
| 5473 | } |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5474 | |
| 5475 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5476 | inline _LIBCPP_INLINE_VISIBILITY |
| 5477 | void |
| 5478 | swap(match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5479 | match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5480 | { |
| 5481 | __x.swap(__y); |
| 5482 | } |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5483 | |
| 5484 | // regex_search |
| 5485 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5486 | template <class _CharT, class _Traits> |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5487 | template <class _Allocator> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5488 | bool |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5489 | basic_regex<_CharT, _Traits>::__match_at_start_ecma( |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5490 | const _CharT* __first, const _CharT* __last, |
| 5491 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5492 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5493 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5494 | vector<__state> __states; |
| 5495 | ptrdiff_t __j = 0; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5496 | ptrdiff_t _N = _VSTD::distance(__first, __last); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5497 | __node* __st = __start_.get(); |
| 5498 | if (__st) |
| 5499 | { |
| 5500 | __states.push_back(__state()); |
| 5501 | __states.back().__do_ = 0; |
| 5502 | __states.back().__first_ = __first; |
| 5503 | __states.back().__current_ = __first; |
| 5504 | __states.back().__last_ = __last; |
| 5505 | __states.back().__sub_matches_.resize(mark_count()); |
| 5506 | __states.back().__loop_data_.resize(__loop_count()); |
| 5507 | __states.back().__node_ = __st; |
| 5508 | __states.back().__flags_ = __flags; |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5509 | __states.back().__at_first_ = __at_first; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5510 | bool __matched = false; |
| 5511 | do |
| 5512 | { |
| 5513 | __state& __s = __states.back(); |
| 5514 | if (__s.__node_) |
| 5515 | __s.__node_->__exec(__s); |
| 5516 | switch (__s.__do_) |
| 5517 | { |
| 5518 | case __state::__end_state: |
| 5519 | __m.__matches_[0].first = __first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5520 | __m.__matches_[0].second = _VSTD::next(__first, __s.__current_ - __first); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5521 | __m.__matches_[0].matched = true; |
| 5522 | for (unsigned __i = 0; __i < __s.__sub_matches_.size(); ++__i) |
| 5523 | __m.__matches_[__i+1] = __s.__sub_matches_[__i]; |
| 5524 | return true; |
| 5525 | case __state::__accept_and_consume: |
| 5526 | case __state::__repeat: |
| 5527 | case __state::__accept_but_not_consume: |
| 5528 | break; |
| 5529 | case __state::__split: |
| 5530 | { |
| 5531 | __state __snext = __s; |
| 5532 | __s.__node_->__exec_split(true, __s); |
| 5533 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5534 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5535 | } |
| 5536 | break; |
| 5537 | case __state::__reject: |
| 5538 | __states.pop_back(); |
| 5539 | break; |
| 5540 | default: |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 5541 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5542 | throw regex_error(regex_constants::__re_err_unknown); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 5543 | #endif |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5544 | break; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 5545 | |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5546 | } |
| 5547 | } while (!__states.empty()); |
| 5548 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5549 | return false; |
| 5550 | } |
| 5551 | |
| 5552 | template <class _CharT, class _Traits> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5553 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5554 | bool |
| 5555 | basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs( |
| 5556 | const _CharT* __first, const _CharT* __last, |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5557 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5558 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5559 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5560 | deque<__state> __states; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5561 | ptrdiff_t __highest_j = 0; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5562 | ptrdiff_t _N = _VSTD::distance(__first, __last); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5563 | __node* __st = __start_.get(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5564 | if (__st) |
| 5565 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5566 | __states.push_back(__state()); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5567 | __states.back().__do_ = 0; |
| 5568 | __states.back().__first_ = __first; |
| 5569 | __states.back().__current_ = __first; |
| 5570 | __states.back().__last_ = __last; |
| 5571 | __states.back().__loop_data_.resize(__loop_count()); |
| 5572 | __states.back().__node_ = __st; |
| 5573 | __states.back().__flags_ = __flags; |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5574 | __states.back().__at_first_ = __at_first; |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5575 | bool __matched = false; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5576 | do |
| 5577 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5578 | __state& __s = __states.back(); |
| 5579 | if (__s.__node_) |
| 5580 | __s.__node_->__exec(__s); |
| 5581 | switch (__s.__do_) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5582 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5583 | case __state::__end_state: |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5584 | if (!__matched || __highest_j < __s.__current_ - __s.__first_) |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5585 | __highest_j = __s.__current_ - __s.__first_; |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5586 | __matched = true; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5587 | if (__highest_j == _N) |
| 5588 | __states.clear(); |
| 5589 | else |
| 5590 | __states.pop_back(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5591 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5592 | case __state::__consume_input: |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5593 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5594 | case __state::__accept_and_consume: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5595 | __states.push_front(_VSTD::move(__s)); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5596 | __states.pop_back(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5597 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5598 | case __state::__repeat: |
| 5599 | case __state::__accept_but_not_consume: |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5600 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5601 | case __state::__split: |
| 5602 | { |
| 5603 | __state __snext = __s; |
| 5604 | __s.__node_->__exec_split(true, __s); |
| 5605 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5606 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5607 | } |
| 5608 | break; |
| 5609 | case __state::__reject: |
| 5610 | __states.pop_back(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5611 | break; |
| 5612 | default: |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 5613 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5614 | throw regex_error(regex_constants::__re_err_unknown); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 5615 | #endif |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5616 | break; |
| 5617 | } |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5618 | } while (!__states.empty()); |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5619 | if (__matched) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5620 | { |
| 5621 | __m.__matches_[0].first = __first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5622 | __m.__matches_[0].second = _VSTD::next(__first, __highest_j); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5623 | __m.__matches_[0].matched = true; |
| 5624 | return true; |
| 5625 | } |
| 5626 | } |
| 5627 | return false; |
| 5628 | } |
| 5629 | |
| 5630 | template <class _CharT, class _Traits> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5631 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5632 | bool |
| 5633 | basic_regex<_CharT, _Traits>::__match_at_start_posix_subs( |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5634 | const _CharT* __first, const _CharT* __last, |
| 5635 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5636 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5637 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5638 | vector<__state> __states; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5639 | __state __best_state; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5640 | ptrdiff_t __j = 0; |
| 5641 | ptrdiff_t __highest_j = 0; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5642 | ptrdiff_t _N = _VSTD::distance(__first, __last); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5643 | __node* __st = __start_.get(); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5644 | if (__st) |
| 5645 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5646 | __states.push_back(__state()); |
| 5647 | __states.back().__do_ = 0; |
| 5648 | __states.back().__first_ = __first; |
| 5649 | __states.back().__current_ = __first; |
| 5650 | __states.back().__last_ = __last; |
| 5651 | __states.back().__sub_matches_.resize(mark_count()); |
| 5652 | __states.back().__loop_data_.resize(__loop_count()); |
| 5653 | __states.back().__node_ = __st; |
| 5654 | __states.back().__flags_ = __flags; |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5655 | __states.back().__at_first_ = __at_first; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5656 | const _CharT* __current = __first; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5657 | bool __matched = false; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5658 | do |
| 5659 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5660 | __state& __s = __states.back(); |
| 5661 | if (__s.__node_) |
| 5662 | __s.__node_->__exec(__s); |
| 5663 | switch (__s.__do_) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5664 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5665 | case __state::__end_state: |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5666 | if (!__matched || __highest_j < __s.__current_ - __s.__first_) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5667 | { |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5668 | __highest_j = __s.__current_ - __s.__first_; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5669 | __best_state = __s; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5670 | } |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5671 | __matched = true; |
| 5672 | if (__highest_j == _N) |
| 5673 | __states.clear(); |
| 5674 | else |
| 5675 | __states.pop_back(); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5676 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5677 | case __state::__accept_and_consume: |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 5678 | __j += __s.__current_ - __current; |
| 5679 | __current = __s.__current_; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5680 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5681 | case __state::__repeat: |
| 5682 | case __state::__accept_but_not_consume: |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5683 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5684 | case __state::__split: |
| 5685 | { |
| 5686 | __state __snext = __s; |
| 5687 | __s.__node_->__exec_split(true, __s); |
| 5688 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5689 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5690 | } |
| 5691 | break; |
| 5692 | case __state::__reject: |
| 5693 | __states.pop_back(); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5694 | break; |
| 5695 | default: |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 5696 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5697 | throw regex_error(regex_constants::__re_err_unknown); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 5698 | #endif |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5699 | break; |
| 5700 | } |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5701 | } while (!__states.empty()); |
| 5702 | if (__matched) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5703 | { |
| 5704 | __m.__matches_[0].first = __first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5705 | __m.__matches_[0].second = _VSTD::next(__first, __highest_j); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5706 | __m.__matches_[0].matched = true; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5707 | for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i) |
| 5708 | __m.__matches_[__i+1] = __best_state.__sub_matches_[__i]; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5709 | return true; |
| 5710 | } |
| 5711 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5712 | return false; |
| 5713 | } |
| 5714 | |
| 5715 | template <class _CharT, class _Traits> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5716 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5717 | bool |
| 5718 | basic_regex<_CharT, _Traits>::__match_at_start( |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5719 | const _CharT* __first, const _CharT* __last, |
| 5720 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5721 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5722 | { |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5723 | if ((__flags_ & 0x1F0) == ECMAScript) |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5724 | return __match_at_start_ecma(__first, __last, __m, __flags, __at_first); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5725 | if (mark_count() == 0) |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5726 | return __match_at_start_posix_nosubs(__first, __last, __m, __flags, __at_first); |
| 5727 | return __match_at_start_posix_subs(__first, __last, __m, __flags, __at_first); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5728 | } |
| 5729 | |
| 5730 | template <class _CharT, class _Traits> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5731 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5732 | bool |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5733 | basic_regex<_CharT, _Traits>::__search( |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5734 | const _CharT* __first, const _CharT* __last, |
| 5735 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5736 | regex_constants::match_flag_type __flags) const |
| 5737 | { |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5738 | __m.__init(1 + mark_count(), __first, __last, |
| 5739 | __flags & regex_constants::__no_update_pos); |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5740 | if (__match_at_start(__first, __last, __m, __flags, true)) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5741 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5742 | __m.__prefix_.second = __m[0].first; |
| 5743 | __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; |
| 5744 | __m.__suffix_.first = __m[0].second; |
| 5745 | __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; |
| 5746 | return true; |
| 5747 | } |
Howard Hinnant | 8daa733 | 2010-07-29 01:15:27 +0000 | [diff] [blame] | 5748 | if (__first != __last && !(__flags & regex_constants::match_continuous)) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5749 | { |
Howard Hinnant | f3dcca0 | 2010-07-29 15:17:28 +0000 | [diff] [blame] | 5750 | __flags |= regex_constants::match_prev_avail; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5751 | for (++__first; __first != __last; ++__first) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5752 | { |
Howard Hinnant | f3dcca0 | 2010-07-29 15:17:28 +0000 | [diff] [blame] | 5753 | __m.__matches_.assign(__m.size(), __m.__unmatched_); |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5754 | if (__match_at_start(__first, __last, __m, __flags, false)) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5755 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5756 | __m.__prefix_.second = __m[0].first; |
| 5757 | __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; |
| 5758 | __m.__suffix_.first = __m[0].second; |
| 5759 | __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; |
| 5760 | return true; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5761 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5762 | __m.__matches_.assign(__m.size(), __m.__unmatched_); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5763 | } |
| 5764 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5765 | __m.__matches_.clear(); |
| 5766 | return false; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5767 | } |
| 5768 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5769 | template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5770 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5771 | bool |
| 5772 | regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 5773 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 5774 | const basic_regex<_CharT, _Traits>& __e, |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5775 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5776 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5777 | basic_string<_CharT> __s(__first, __last); |
| 5778 | match_results<const _CharT*> __mc; |
| 5779 | bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5780 | __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5781 | return __r; |
| 5782 | } |
| 5783 | |
| 5784 | template <class _Allocator, class _CharT, class _Traits> |
| 5785 | inline _LIBCPP_INLINE_VISIBILITY |
| 5786 | bool |
| 5787 | regex_search(const _CharT* __first, const _CharT* __last, |
| 5788 | match_results<const _CharT*, _Allocator>& __m, |
| 5789 | const basic_regex<_CharT, _Traits>& __e, |
| 5790 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5791 | { |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5792 | return __e.__search(__first, __last, __m, __flags); |
| 5793 | } |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5794 | |
| 5795 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 5796 | inline _LIBCPP_INLINE_VISIBILITY |
| 5797 | bool |
| 5798 | regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 5799 | const basic_regex<_CharT, _Traits>& __e, |
| 5800 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5801 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5802 | basic_string<_CharT> __s(__first, __last); |
| 5803 | match_results<const _CharT*> __mc; |
| 5804 | return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
| 5805 | } |
| 5806 | |
| 5807 | template <class _CharT, class _Traits> |
| 5808 | inline _LIBCPP_INLINE_VISIBILITY |
| 5809 | bool |
| 5810 | regex_search(const _CharT* __first, const _CharT* __last, |
| 5811 | const basic_regex<_CharT, _Traits>& __e, |
| 5812 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5813 | { |
| 5814 | match_results<const _CharT*> __mc; |
| 5815 | return __e.__search(__first, __last, __mc, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5816 | } |
| 5817 | |
| 5818 | template <class _CharT, class _Allocator, class _Traits> |
| 5819 | inline _LIBCPP_INLINE_VISIBILITY |
| 5820 | bool |
| 5821 | regex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, |
| 5822 | const basic_regex<_CharT, _Traits>& __e, |
| 5823 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5824 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5825 | return __e.__search(__str, __str + _Traits::length(__str), __m, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5826 | } |
| 5827 | |
| 5828 | template <class _CharT, class _Traits> |
| 5829 | inline _LIBCPP_INLINE_VISIBILITY |
| 5830 | bool |
| 5831 | regex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, |
| 5832 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5833 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5834 | match_results<const _CharT*> __m; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5835 | return _VSTD::regex_search(__str, __m, __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5836 | } |
| 5837 | |
| 5838 | template <class _ST, class _SA, class _CharT, class _Traits> |
| 5839 | inline _LIBCPP_INLINE_VISIBILITY |
| 5840 | bool |
| 5841 | regex_search(const basic_string<_CharT, _ST, _SA>& __s, |
| 5842 | const basic_regex<_CharT, _Traits>& __e, |
| 5843 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5844 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5845 | match_results<const _CharT*> __mc; |
| 5846 | return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5847 | } |
| 5848 | |
| 5849 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 5850 | inline _LIBCPP_INLINE_VISIBILITY |
| 5851 | bool |
| 5852 | regex_search(const basic_string<_CharT, _ST, _SA>& __s, |
| 5853 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 5854 | const basic_regex<_CharT, _Traits>& __e, |
| 5855 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5856 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5857 | match_results<const _CharT*> __mc; |
| 5858 | bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5859 | __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] | 5860 | return __r; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5861 | } |
| 5862 | |
| 5863 | // regex_match |
| 5864 | |
| 5865 | template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> |
| 5866 | bool |
| 5867 | regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 5868 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 5869 | const basic_regex<_CharT, _Traits>& __e, |
| 5870 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5871 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5872 | bool __r = _VSTD::regex_search(__first, __last, __m, __e, |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5873 | __flags | regex_constants::match_continuous); |
| 5874 | if (__r) |
| 5875 | { |
| 5876 | __r = !__m.suffix().matched; |
| 5877 | if (!__r) |
| 5878 | __m.__matches_.clear(); |
| 5879 | } |
| 5880 | return __r; |
| 5881 | } |
| 5882 | |
| 5883 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 5884 | inline _LIBCPP_INLINE_VISIBILITY |
| 5885 | bool |
| 5886 | regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 5887 | const basic_regex<_CharT, _Traits>& __e, |
| 5888 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5889 | { |
| 5890 | match_results<_BidirectionalIterator> __m; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5891 | return _VSTD::regex_match(__first, __last, __m, __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5892 | } |
| 5893 | |
| 5894 | template <class _CharT, class _Allocator, class _Traits> |
| 5895 | inline _LIBCPP_INLINE_VISIBILITY |
| 5896 | bool |
| 5897 | regex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, |
| 5898 | const basic_regex<_CharT, _Traits>& __e, |
| 5899 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5900 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5901 | return _VSTD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5902 | } |
| 5903 | |
| 5904 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 5905 | inline _LIBCPP_INLINE_VISIBILITY |
| 5906 | bool |
| 5907 | regex_match(const basic_string<_CharT, _ST, _SA>& __s, |
| 5908 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 5909 | const basic_regex<_CharT, _Traits>& __e, |
| 5910 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5911 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5912 | return _VSTD::regex_match(__s.begin(), __s.end(), __m, __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5913 | } |
| 5914 | |
| 5915 | template <class _CharT, class _Traits> |
| 5916 | inline _LIBCPP_INLINE_VISIBILITY |
| 5917 | bool |
| 5918 | regex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, |
| 5919 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5920 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5921 | return _VSTD::regex_match(__str, __str + _Traits::length(__str), __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5922 | } |
| 5923 | |
| 5924 | template <class _ST, class _SA, class _CharT, class _Traits> |
| 5925 | inline _LIBCPP_INLINE_VISIBILITY |
| 5926 | bool |
| 5927 | regex_match(const basic_string<_CharT, _ST, _SA>& __s, |
| 5928 | const basic_regex<_CharT, _Traits>& __e, |
| 5929 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5930 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5931 | return _VSTD::regex_match(__s.begin(), __s.end(), __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5932 | } |
| 5933 | |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5934 | // regex_iterator |
| 5935 | |
| 5936 | template <class _BidirectionalIterator, |
| 5937 | class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type, |
| 5938 | class _Traits = regex_traits<_CharT> > |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5939 | class _LIBCPP_VISIBLE regex_iterator |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5940 | { |
| 5941 | public: |
| 5942 | typedef basic_regex<_CharT, _Traits> regex_type; |
| 5943 | typedef match_results<_BidirectionalIterator> value_type; |
| 5944 | typedef ptrdiff_t difference_type; |
| 5945 | typedef const value_type* pointer; |
| 5946 | typedef const value_type& reference; |
| 5947 | typedef forward_iterator_tag iterator_category; |
| 5948 | |
| 5949 | private: |
| 5950 | _BidirectionalIterator __begin_; |
| 5951 | _BidirectionalIterator __end_; |
| 5952 | const regex_type* __pregex_; |
| 5953 | regex_constants::match_flag_type __flags_; |
| 5954 | value_type __match_; |
| 5955 | |
| 5956 | public: |
| 5957 | regex_iterator(); |
| 5958 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 5959 | const regex_type& __re, |
| 5960 | regex_constants::match_flag_type __m = regex_constants::match_default); |
| 5961 | |
| 5962 | bool operator==(const regex_iterator& __x) const; |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5963 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5964 | bool operator!=(const regex_iterator& __x) const {return !(*this == __x);} |
| 5965 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5966 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5967 | reference operator*() const {return __match_;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5968 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5969 | pointer operator->() const {return &__match_;} |
| 5970 | |
| 5971 | regex_iterator& operator++(); |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5972 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5973 | regex_iterator operator++(int) |
| 5974 | { |
| 5975 | regex_iterator __t(*this); |
| 5976 | ++(*this); |
| 5977 | return __t; |
| 5978 | } |
| 5979 | }; |
| 5980 | |
| 5981 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 5982 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_iterator() |
| 5983 | : __begin_(), __end_(), __pregex_(nullptr), __flags_(), __match_() |
| 5984 | { |
| 5985 | } |
| 5986 | |
| 5987 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 5988 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 5989 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 5990 | const regex_type& __re, regex_constants::match_flag_type __m) |
| 5991 | : __begin_(__a), |
| 5992 | __end_(__b), |
| 5993 | __pregex_(&__re), |
| 5994 | __flags_(__m) |
| 5995 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5996 | _VSTD::regex_search(__begin_, __end_, __match_, *__pregex_, __flags_); |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5997 | } |
| 5998 | |
| 5999 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6000 | bool |
| 6001 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6002 | operator==(const regex_iterator& __x) const |
| 6003 | { |
| 6004 | if (__match_.empty() && __x.__match_.empty()) |
| 6005 | return true; |
| 6006 | if (__match_.empty() || __x.__match_.empty()) |
| 6007 | return false; |
| 6008 | return __begin_ == __x.__begin_ && |
| 6009 | __end_ == __x.__end_ && |
| 6010 | __pregex_ == __x.__pregex_ && |
| 6011 | __flags_ == __x.__flags_ && |
| 6012 | __match_[0] == __x.__match_[0]; |
| 6013 | } |
| 6014 | |
| 6015 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6016 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6017 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() |
| 6018 | { |
| 6019 | __flags_ |= regex_constants::__no_update_pos; |
| 6020 | _BidirectionalIterator __start = __match_[0].second; |
| 6021 | if (__match_.length() == 0) |
| 6022 | { |
| 6023 | if (__start == __end_) |
| 6024 | { |
| 6025 | __match_ = value_type(); |
| 6026 | return *this; |
| 6027 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6028 | else if (_VSTD::regex_search(__start, __end_, __match_, *__pregex_, |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6029 | __flags_ | regex_constants::match_not_null | |
| 6030 | regex_constants::match_continuous)) |
| 6031 | return *this; |
| 6032 | else |
| 6033 | ++__start; |
| 6034 | } |
| 6035 | __flags_ |= regex_constants::match_prev_avail; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6036 | if (!_VSTD::regex_search(__start, __end_, __match_, *__pregex_, __flags_)) |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6037 | __match_ = value_type(); |
| 6038 | return *this; |
| 6039 | } |
| 6040 | |
| 6041 | typedef regex_iterator<const char*> cregex_iterator; |
| 6042 | typedef regex_iterator<const wchar_t*> wcregex_iterator; |
| 6043 | typedef regex_iterator<string::const_iterator> sregex_iterator; |
| 6044 | typedef regex_iterator<wstring::const_iterator> wsregex_iterator; |
| 6045 | |
| 6046 | // regex_token_iterator |
| 6047 | |
| 6048 | template <class _BidirectionalIterator, |
| 6049 | class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type, |
| 6050 | class _Traits = regex_traits<_CharT> > |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6051 | class _LIBCPP_VISIBLE regex_token_iterator |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6052 | { |
| 6053 | public: |
| 6054 | typedef basic_regex<_CharT, _Traits> regex_type; |
| 6055 | typedef sub_match<_BidirectionalIterator> value_type; |
| 6056 | typedef ptrdiff_t difference_type; |
| 6057 | typedef const value_type* pointer; |
| 6058 | typedef const value_type& reference; |
| 6059 | typedef forward_iterator_tag iterator_category; |
| 6060 | |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6061 | private: |
| 6062 | typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position; |
| 6063 | |
| 6064 | _Position __position_; |
| 6065 | const value_type* __result_; |
| 6066 | value_type __suffix_; |
| 6067 | ptrdiff_t _N_; |
| 6068 | vector<int> __subs_; |
| 6069 | |
| 6070 | public: |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6071 | regex_token_iterator(); |
| 6072 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6073 | const regex_type& __re, int __submatch = 0, |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6074 | regex_constants::match_flag_type __m = |
| 6075 | regex_constants::match_default); |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6076 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6077 | const regex_type& __re, const vector<int>& __submatches, |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6078 | regex_constants::match_flag_type __m = |
| 6079 | regex_constants::match_default); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6080 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6081 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6082 | const regex_type& __re, |
| 6083 | initializer_list<int> __submatches, |
| 6084 | regex_constants::match_flag_type __m = |
| 6085 | regex_constants::match_default); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6086 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6087 | template <size_t _N> |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6088 | regex_token_iterator(_BidirectionalIterator __a, |
| 6089 | _BidirectionalIterator __b, |
| 6090 | const regex_type& __re, |
| 6091 | const int (&__submatches)[_N], |
| 6092 | regex_constants::match_flag_type __m = |
| 6093 | regex_constants::match_default); |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6094 | regex_token_iterator(const regex_token_iterator&); |
| 6095 | regex_token_iterator& operator=(const regex_token_iterator&); |
| 6096 | |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6097 | bool operator==(const regex_token_iterator& __x) const; |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6098 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6099 | bool operator!=(const regex_token_iterator& __x) const {return !(*this == __x);} |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6100 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6101 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6102 | const value_type& operator*() const {return *__result_;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6103 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6104 | const value_type* operator->() const {return __result_;} |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6105 | |
| 6106 | regex_token_iterator& operator++(); |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6107 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6108 | regex_token_iterator operator++(int) |
| 6109 | { |
| 6110 | regex_token_iterator __t(*this); |
| 6111 | ++(*this); |
| 6112 | return __t; |
| 6113 | } |
| 6114 | |
| 6115 | private: |
| 6116 | void __init(_BidirectionalIterator __a, _BidirectionalIterator __b); |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6117 | }; |
| 6118 | |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6119 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6120 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6121 | regex_token_iterator() |
| 6122 | : __result_(nullptr), |
| 6123 | __suffix_(), |
| 6124 | _N_(0) |
| 6125 | { |
| 6126 | } |
| 6127 | |
| 6128 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6129 | void |
| 6130 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6131 | __init(_BidirectionalIterator __a, _BidirectionalIterator __b) |
| 6132 | { |
| 6133 | if (__position_ != _Position()) |
| 6134 | { |
| 6135 | if (__subs_[_N_] == -1) |
| 6136 | __result_ = &__position_->prefix(); |
| 6137 | else |
| 6138 | __result_ = &(*__position_)[__subs_[_N_]]; |
| 6139 | } |
| 6140 | else if (__subs_[_N_] == -1) |
| 6141 | { |
| 6142 | __suffix_.matched = true; |
| 6143 | __suffix_.first = __a; |
| 6144 | __suffix_.second = __b; |
| 6145 | __result_ = &__suffix_; |
| 6146 | } |
| 6147 | else |
| 6148 | __result_ = nullptr; |
| 6149 | } |
| 6150 | |
| 6151 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6152 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6153 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6154 | const regex_type& __re, int __submatch, |
| 6155 | regex_constants::match_flag_type __m) |
| 6156 | : __position_(__a, __b, __re, __m), |
| 6157 | _N_(0), |
| 6158 | __subs_(1, __submatch) |
| 6159 | { |
| 6160 | __init(__a, __b); |
| 6161 | } |
| 6162 | |
| 6163 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6164 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6165 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6166 | const regex_type& __re, const vector<int>& __submatches, |
| 6167 | regex_constants::match_flag_type __m) |
| 6168 | : __position_(__a, __b, __re, __m), |
| 6169 | _N_(0), |
| 6170 | __subs_(__submatches) |
| 6171 | { |
| 6172 | __init(__a, __b); |
| 6173 | } |
| 6174 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6175 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 6176 | |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6177 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6178 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6179 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6180 | const regex_type& __re, |
| 6181 | initializer_list<int> __submatches, |
| 6182 | regex_constants::match_flag_type __m) |
| 6183 | : __position_(__a, __b, __re, __m), |
| 6184 | _N_(0), |
| 6185 | __subs_(__submatches) |
| 6186 | { |
| 6187 | __init(__a, __b); |
| 6188 | } |
| 6189 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6190 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 6191 | |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6192 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6193 | template <size_t _N> |
| 6194 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6195 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6196 | const regex_type& __re, |
| 6197 | const int (&__submatches)[_N], |
| 6198 | regex_constants::match_flag_type __m) |
| 6199 | : __position_(__a, __b, __re, __m), |
| 6200 | _N_(0), |
| 6201 | __subs_(__submatches, __submatches + _N) |
| 6202 | { |
| 6203 | __init(__a, __b); |
| 6204 | } |
| 6205 | |
| 6206 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6207 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6208 | regex_token_iterator(const regex_token_iterator& __x) |
| 6209 | : __position_(__x.__position_), |
| 6210 | __result_(__x.__result_), |
| 6211 | __suffix_(__x.__suffix_), |
| 6212 | _N_(__x._N_), |
| 6213 | __subs_(__x.__subs_) |
| 6214 | { |
| 6215 | if (__x.__result_ == &__x.__suffix_) |
| 6216 | __result_ == &__suffix_; |
| 6217 | } |
| 6218 | |
| 6219 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6220 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6221 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6222 | operator=(const regex_token_iterator& __x) |
| 6223 | { |
| 6224 | if (this != &__x) |
| 6225 | { |
| 6226 | __position_ = __x.__position_; |
| 6227 | if (__x.__result_ == &__x.__suffix_) |
| 6228 | __result_ == &__suffix_; |
| 6229 | else |
| 6230 | __result_ = __x.__result_; |
| 6231 | __suffix_ = __x.__suffix_; |
| 6232 | _N_ = __x._N_; |
| 6233 | __subs_ = __x.__subs_; |
| 6234 | } |
| 6235 | return *this; |
| 6236 | } |
| 6237 | |
| 6238 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6239 | bool |
| 6240 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6241 | operator==(const regex_token_iterator& __x) const |
| 6242 | { |
| 6243 | if (__result_ == nullptr && __x.__result_ == nullptr) |
| 6244 | return true; |
| 6245 | if (__result_ == &__suffix_ && __x.__result_ == &__x.__suffix_ && |
| 6246 | __suffix_ == __x.__suffix_) |
| 6247 | return true; |
| 6248 | if (__result_ == nullptr || __x.__result_ == nullptr) |
| 6249 | return false; |
| 6250 | if (__result_ == &__suffix_ || __x.__result_ == &__x.__suffix_) |
| 6251 | return false; |
| 6252 | return __position_ == __x.__position_ && _N_ == __x._N_ && |
| 6253 | __subs_ == __x.__subs_; |
| 6254 | } |
| 6255 | |
| 6256 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6257 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6258 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() |
| 6259 | { |
| 6260 | _Position __prev = __position_; |
| 6261 | if (__result_ == &__suffix_) |
| 6262 | __result_ = nullptr; |
| 6263 | else if (_N_ + 1 < __subs_.size()) |
| 6264 | { |
| 6265 | ++_N_; |
| 6266 | if (__subs_[_N_] == -1) |
| 6267 | __result_ = &__position_->prefix(); |
| 6268 | else |
| 6269 | __result_ = &(*__position_)[__subs_[_N_]]; |
| 6270 | } |
| 6271 | else |
| 6272 | { |
| 6273 | _N_ = 0; |
| 6274 | ++__position_; |
| 6275 | if (__position_ != _Position()) |
| 6276 | { |
| 6277 | if (__subs_[_N_] == -1) |
| 6278 | __result_ = &__position_->prefix(); |
| 6279 | else |
| 6280 | __result_ = &(*__position_)[__subs_[_N_]]; |
| 6281 | } |
| 6282 | else |
| 6283 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6284 | if (_VSTD::find(__subs_.begin(), __subs_.end(), -1) != __subs_.end() |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6285 | && __prev->suffix().length() != 0) |
| 6286 | { |
| 6287 | __suffix_.matched = true; |
| 6288 | __suffix_.first = __prev->suffix().first; |
| 6289 | __suffix_.second = __prev->suffix().second; |
| 6290 | __result_ = &__suffix_; |
| 6291 | } |
| 6292 | else |
| 6293 | __result_ = nullptr; |
| 6294 | } |
| 6295 | } |
| 6296 | return *this; |
| 6297 | } |
| 6298 | |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6299 | typedef regex_token_iterator<const char*> cregex_token_iterator; |
| 6300 | typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator; |
| 6301 | typedef regex_token_iterator<string::const_iterator> sregex_token_iterator; |
| 6302 | typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator; |
| 6303 | |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6304 | // regex_replace |
| 6305 | |
| 6306 | template <class _OutputIterator, class _BidirectionalIterator, |
| 6307 | class _Traits, class _CharT> |
| 6308 | _OutputIterator |
| 6309 | regex_replace(_OutputIterator __out, |
| 6310 | _BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6311 | const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt, |
| 6312 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6313 | { |
| 6314 | typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Iter; |
| 6315 | _Iter __i(__first, __last, __e, __flags); |
| 6316 | _Iter __eof; |
| 6317 | if (__i == __eof) |
| 6318 | { |
| 6319 | if (!(__flags & regex_constants::format_no_copy)) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6320 | __out = _VSTD::copy(__first, __last, __out); |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6321 | } |
| 6322 | else |
| 6323 | { |
| 6324 | sub_match<_BidirectionalIterator> __lm; |
| 6325 | for (size_t __len = char_traits<_CharT>::length(__fmt); __i != __eof; ++__i) |
| 6326 | { |
| 6327 | if (!(__flags & regex_constants::format_no_copy)) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6328 | __out = _VSTD::copy(__i->prefix().first, __i->prefix().second, __out); |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6329 | __out = __i->format(__out, __fmt, __fmt + __len, __flags); |
| 6330 | __lm = __i->suffix(); |
| 6331 | if (__flags & regex_constants::format_first_only) |
| 6332 | break; |
| 6333 | } |
| 6334 | if (!(__flags & regex_constants::format_no_copy)) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6335 | __out = _VSTD::copy(__lm.first, __lm.second, __out); |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6336 | } |
| 6337 | return __out; |
| 6338 | } |
| 6339 | |
| 6340 | template <class _OutputIterator, class _BidirectionalIterator, |
| 6341 | class _Traits, class _CharT, class _ST, class _SA> |
| 6342 | inline _LIBCPP_INLINE_VISIBILITY |
| 6343 | _OutputIterator |
| 6344 | regex_replace(_OutputIterator __out, |
| 6345 | _BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6346 | const basic_regex<_CharT, _Traits>& __e, |
| 6347 | const basic_string<_CharT, _ST, _SA>& __fmt, |
| 6348 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6349 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6350 | return _VSTD::regex_replace(__out, __first, __last, __e, __fmt.c_str(), __flags); |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6351 | } |
| 6352 | |
| 6353 | template <class _Traits, class _CharT, class _ST, class _SA, class _FST, |
| 6354 | class _FSA> |
| 6355 | inline _LIBCPP_INLINE_VISIBILITY |
| 6356 | basic_string<_CharT, _ST, _SA> |
| 6357 | regex_replace(const basic_string<_CharT, _ST, _SA>& __s, |
| 6358 | const basic_regex<_CharT, _Traits>& __e, |
| 6359 | const basic_string<_CharT, _FST, _FSA>& __fmt, |
| 6360 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6361 | { |
| 6362 | basic_string<_CharT, _ST, _SA> __r; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6363 | _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e, |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6364 | __fmt.c_str(), __flags); |
| 6365 | return __r; |
| 6366 | } |
| 6367 | |
| 6368 | template <class _Traits, class _CharT, class _ST, class _SA> |
| 6369 | inline _LIBCPP_INLINE_VISIBILITY |
| 6370 | basic_string<_CharT, _ST, _SA> |
| 6371 | regex_replace(const basic_string<_CharT, _ST, _SA>& __s, |
| 6372 | const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt, |
| 6373 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6374 | { |
| 6375 | basic_string<_CharT, _ST, _SA> __r; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6376 | _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e, |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6377 | __fmt, __flags); |
| 6378 | return __r; |
| 6379 | } |
| 6380 | |
| 6381 | template <class _Traits, class _CharT, class _ST, class _SA> |
| 6382 | inline _LIBCPP_INLINE_VISIBILITY |
| 6383 | basic_string<_CharT> |
| 6384 | regex_replace(const _CharT* __s, |
| 6385 | const basic_regex<_CharT, _Traits>& __e, |
| 6386 | const basic_string<_CharT, _ST, _SA>& __fmt, |
| 6387 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6388 | { |
| 6389 | basic_string<_CharT> __r; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6390 | _VSTD::regex_replace(back_inserter(__r), __s, |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6391 | __s + char_traits<_CharT>::length(__s), __e, |
| 6392 | __fmt.c_str(), __flags); |
| 6393 | return __r; |
| 6394 | } |
| 6395 | |
| 6396 | template <class _Traits, class _CharT> |
| 6397 | inline _LIBCPP_INLINE_VISIBILITY |
| 6398 | basic_string<_CharT> |
| 6399 | regex_replace(const _CharT* __s, |
| 6400 | const basic_regex<_CharT, _Traits>& __e, |
| 6401 | const _CharT* __fmt, |
| 6402 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6403 | { |
| 6404 | basic_string<_CharT> __r; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6405 | _VSTD::regex_replace(back_inserter(__r), __s, |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6406 | __s + char_traits<_CharT>::length(__s), __e, |
| 6407 | __fmt, __flags); |
| 6408 | return __r; |
| 6409 | } |
| 6410 | |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 6411 | _LIBCPP_END_NAMESPACE_STD |
| 6412 | |
| 6413 | #endif // _LIBCPP_REGEX |