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