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