Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===--------------------------- regex ------------------------------------===// |
| 3 | // |
| 4 | // The LLVM Compiler Infrastructure |
| 5 | // |
| 6 | // This file is distributed under the University of Illinois Open Source |
| 7 | // License. See LICENSE.TXT for details. |
| 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 | |
| 211 | difference_type length() const; |
| 212 | operator string_type() const; |
| 213 | string_type str() const; |
| 214 | |
| 215 | int compare(const sub_match& s) const; |
| 216 | int compare(const string_type& s) const; |
| 217 | int compare(const value_type* s) const; |
| 218 | }; |
| 219 | |
| 220 | typedef sub_match<const char*> csub_match; |
| 221 | typedef sub_match<const wchar_t*> wcsub_match; |
| 222 | typedef sub_match<string::const_iterator> ssub_match; |
| 223 | typedef sub_match<wstring::const_iterator> wssub_match; |
| 224 | |
| 225 | template <class BiIter> |
| 226 | bool |
| 227 | operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); |
| 228 | |
| 229 | template <class BiIter> |
| 230 | bool |
| 231 | operator!=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); |
| 232 | |
| 233 | template <class BiIter> |
| 234 | bool |
| 235 | operator<(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); |
| 236 | |
| 237 | template <class BiIter> |
| 238 | bool |
| 239 | operator<=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); |
| 240 | |
| 241 | template <class BiIter> |
| 242 | bool |
| 243 | operator>=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); |
| 244 | |
| 245 | template <class BiIter> |
| 246 | bool |
| 247 | operator>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); |
| 248 | |
| 249 | template <class BiIter, class ST, class SA> |
| 250 | bool |
| 251 | operator==(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 252 | const sub_match<BiIter>& rhs); |
| 253 | |
| 254 | template <class BiIter, class ST, class SA> |
| 255 | bool |
| 256 | operator!=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 257 | const sub_match<BiIter>& rhs); |
| 258 | |
| 259 | template <class BiIter, class ST, class SA> |
| 260 | bool |
| 261 | operator<(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 262 | const sub_match<BiIter>& rhs); |
| 263 | |
| 264 | template <class BiIter, class ST, class SA> |
| 265 | bool |
| 266 | operator>(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 267 | const sub_match<BiIter>& rhs); |
| 268 | |
| 269 | template <class BiIter, class ST, class SA> |
| 270 | bool operator>=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 271 | const sub_match<BiIter>& rhs); |
| 272 | |
| 273 | template <class BiIter, class ST, class SA> |
| 274 | bool |
| 275 | operator<=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 276 | const sub_match<BiIter>& rhs); |
| 277 | |
| 278 | template <class BiIter, class ST, class SA> |
| 279 | bool |
| 280 | operator==(const sub_match<BiIter>& lhs, |
| 281 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 282 | |
| 283 | template <class BiIter, class ST, class SA> |
| 284 | bool |
| 285 | operator!=(const sub_match<BiIter>& lhs, |
| 286 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 287 | |
| 288 | template <class BiIter, class ST, class SA> |
| 289 | bool |
| 290 | operator<(const sub_match<BiIter>& lhs, |
| 291 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 292 | |
| 293 | template <class BiIter, class ST, class SA> |
| 294 | bool operator>(const sub_match<BiIter>& lhs, |
| 295 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 296 | |
| 297 | template <class BiIter, class ST, class SA> |
| 298 | bool |
| 299 | operator>=(const sub_match<BiIter>& lhs, |
| 300 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 301 | |
| 302 | template <class BiIter, class ST, class SA> |
| 303 | bool |
| 304 | operator<=(const sub_match<BiIter>& lhs, |
| 305 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 306 | |
| 307 | template <class BiIter> |
| 308 | bool |
| 309 | operator==(typename iterator_traits<BiIter>::value_type const* lhs, |
| 310 | const sub_match<BiIter>& rhs); |
| 311 | |
| 312 | template <class BiIter> |
| 313 | bool |
| 314 | operator!=(typename iterator_traits<BiIter>::value_type const* lhs, |
| 315 | const sub_match<BiIter>& rhs); |
| 316 | |
| 317 | template <class BiIter> |
| 318 | bool |
| 319 | operator<(typename iterator_traits<BiIter>::value_type const* lhs, |
| 320 | const sub_match<BiIter>& rhs); |
| 321 | |
| 322 | template <class BiIter> |
| 323 | bool |
| 324 | operator>(typename iterator_traits<BiIter>::value_type const* lhs, |
| 325 | const sub_match<BiIter>& rhs); |
| 326 | |
| 327 | template <class BiIter> |
| 328 | bool |
| 329 | operator>=(typename iterator_traits<BiIter>::value_type const* lhs, |
| 330 | const sub_match<BiIter>& rhs); |
| 331 | |
| 332 | template <class BiIter> |
| 333 | bool |
| 334 | operator<=(typename iterator_traits<BiIter>::value_type const* lhs, |
| 335 | const sub_match<BiIter>& rhs); |
| 336 | |
| 337 | template <class BiIter> |
| 338 | bool |
| 339 | operator==(const sub_match<BiIter>& lhs, |
| 340 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 341 | |
| 342 | template <class BiIter> |
| 343 | bool |
| 344 | operator!=(const sub_match<BiIter>& lhs, |
| 345 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 346 | |
| 347 | template <class BiIter> |
| 348 | bool |
| 349 | operator<(const sub_match<BiIter>& lhs, |
| 350 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 351 | |
| 352 | template <class BiIter> |
| 353 | bool |
| 354 | operator>(const sub_match<BiIter>& lhs, |
| 355 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 356 | |
| 357 | template <class BiIter> |
| 358 | bool |
| 359 | operator>=(const sub_match<BiIter>& lhs, |
| 360 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 361 | |
| 362 | template <class BiIter> |
| 363 | bool |
| 364 | operator<=(const sub_match<BiIter>& lhs, |
| 365 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 366 | |
| 367 | template <class BiIter> |
| 368 | bool |
| 369 | operator==(typename iterator_traits<BiIter>::value_type const& lhs, |
| 370 | const sub_match<BiIter>& rhs); |
| 371 | |
| 372 | template <class BiIter> |
| 373 | bool |
| 374 | operator!=(typename iterator_traits<BiIter>::value_type const& lhs, |
| 375 | const sub_match<BiIter>& rhs); |
| 376 | |
| 377 | template <class BiIter> |
| 378 | bool |
| 379 | operator<(typename iterator_traits<BiIter>::value_type const& lhs, |
| 380 | const sub_match<BiIter>& rhs); |
| 381 | |
| 382 | template <class BiIter> |
| 383 | bool |
| 384 | operator>(typename iterator_traits<BiIter>::value_type const& lhs, |
| 385 | const sub_match<BiIter>& rhs); |
| 386 | |
| 387 | template <class BiIter> |
| 388 | bool |
| 389 | operator>=(typename iterator_traits<BiIter>::value_type const& lhs, |
| 390 | const sub_match<BiIter>& rhs); |
| 391 | |
| 392 | template <class BiIter> |
| 393 | bool |
| 394 | operator<=(typename iterator_traits<BiIter>::value_type const& lhs, |
| 395 | const sub_match<BiIter>& rhs); |
| 396 | |
| 397 | template <class BiIter> |
| 398 | bool |
| 399 | operator==(const sub_match<BiIter>& lhs, |
| 400 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 401 | |
| 402 | template <class BiIter> |
| 403 | bool |
| 404 | operator!=(const sub_match<BiIter>& lhs, |
| 405 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 406 | |
| 407 | template <class BiIter> |
| 408 | bool |
| 409 | operator<(const sub_match<BiIter>& lhs, |
| 410 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 411 | |
| 412 | template <class BiIter> |
| 413 | bool |
| 414 | operator>(const sub_match<BiIter>& lhs, |
| 415 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 416 | |
| 417 | template <class BiIter> |
| 418 | bool |
| 419 | operator>=(const sub_match<BiIter>& lhs, |
| 420 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 421 | |
| 422 | template <class BiIter> |
| 423 | bool |
| 424 | operator<=(const sub_match<BiIter>& lhs, |
| 425 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 426 | |
| 427 | template <class charT, class ST, class BiIter> |
| 428 | basic_ostream<charT, ST>& |
| 429 | operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m); |
| 430 | |
| 431 | template <class BidirectionalIterator, |
| 432 | class Allocator = allocator<sub_match<BidirectionalIterator>>> |
| 433 | class match_results |
| 434 | { |
| 435 | public: |
| 436 | typedef sub_match<BidirectionalIterator> value_type; |
| 437 | typedef const value_type& const_reference; |
| 438 | typedef const_reference reference; |
| 439 | typedef /implementation-defined/ const_iterator; |
| 440 | typedef const_iterator iterator; |
| 441 | typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type; |
| 442 | typedef typename allocator_traits<Allocator>::size_type size_type; |
| 443 | typedef Allocator allocator_type; |
| 444 | typedef typename iterator_traits<BidirectionalIterator>::value_type char_type; |
| 445 | typedef basic_string<char_type> string_type; |
| 446 | |
| 447 | // construct/copy/destroy: |
| 448 | explicit match_results(const Allocator& a = Allocator()); |
| 449 | match_results(const match_results& m); |
| 450 | match_results(match_results&& m); |
| 451 | match_results& operator=(const match_results& m); |
| 452 | match_results& operator=(match_results&& m); |
| 453 | ~match_results(); |
| 454 | |
| 455 | // size: |
| 456 | size_type size() const; |
| 457 | size_type max_size() const; |
| 458 | bool empty() const; |
| 459 | |
| 460 | // element access: |
| 461 | difference_type length(size_type sub = 0) const; |
| 462 | difference_type position(size_type sub = 0) const; |
| 463 | string_type str(size_type sub = 0) const; |
| 464 | const_reference operator[](size_type n) const; |
| 465 | |
| 466 | const_reference prefix() const; |
| 467 | const_reference suffix() const; |
| 468 | |
| 469 | const_iterator begin() const; |
| 470 | const_iterator end() const; |
| 471 | const_iterator cbegin() const; |
| 472 | const_iterator cend() const; |
| 473 | |
| 474 | // format: |
| 475 | template <class OutputIter> |
| 476 | OutputIter |
| 477 | format(OutputIter out, const char_type* fmt_first, |
| 478 | const char_type* fmt_last, |
| 479 | regex_constants::match_flag_type flags = regex_constants::format_default) const; |
| 480 | template <class OutputIter, class ST, class SA> |
| 481 | OutputIter |
| 482 | format(OutputIter out, const basic_string<char_type, ST, SA>& fmt, |
| 483 | regex_constants::match_flag_type flags = regex_constants::format_default) const; |
| 484 | template <class ST, class SA> |
| 485 | basic_string<char_type, ST, SA> |
| 486 | format(const basic_string<char_type, ST, SA>& fmt, |
| 487 | regex_constants::match_flag_type flags = regex_constants::format_default) const; |
| 488 | string_type |
| 489 | format(const char_type* fmt, |
| 490 | regex_constants::match_flag_type flags = regex_constants::format_default) const; |
| 491 | |
| 492 | // allocator: |
| 493 | allocator_type get_allocator() const; |
| 494 | |
| 495 | // swap: |
| 496 | void swap(match_results& that); |
| 497 | }; |
| 498 | |
| 499 | typedef match_results<const char*> cmatch; |
| 500 | typedef match_results<const wchar_t*> wcmatch; |
| 501 | typedef match_results<string::const_iterator> smatch; |
| 502 | typedef match_results<wstring::const_iterator> wsmatch; |
| 503 | |
| 504 | template <class BidirectionalIterator, class Allocator> |
| 505 | bool |
| 506 | operator==(const match_results<BidirectionalIterator, Allocator>& m1, |
| 507 | const match_results<BidirectionalIterator, Allocator>& m2); |
| 508 | |
| 509 | template <class BidirectionalIterator, class Allocator> |
| 510 | bool |
| 511 | operator!=(const match_results<BidirectionalIterator, Allocator>& m1, |
| 512 | const match_results<BidirectionalIterator, Allocator>& m2); |
| 513 | |
| 514 | template <class BidirectionalIterator, class Allocator> |
| 515 | void |
| 516 | swap(match_results<BidirectionalIterator, Allocator>& m1, |
| 517 | match_results<BidirectionalIterator, Allocator>& m2); |
| 518 | |
| 519 | template <class BidirectionalIterator, class Allocator, class charT, class traits> |
| 520 | bool |
| 521 | regex_match(BidirectionalIterator first, BidirectionalIterator last, |
| 522 | match_results<BidirectionalIterator, Allocator>& m, |
| 523 | const basic_regex<charT, traits>& e, |
| 524 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 525 | |
| 526 | template <class BidirectionalIterator, class charT, class traits> |
| 527 | bool |
| 528 | regex_match(BidirectionalIterator first, BidirectionalIterator last, |
| 529 | const basic_regex<charT, traits>& e, |
| 530 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 531 | |
| 532 | template <class charT, class Allocator, class traits> |
| 533 | bool |
| 534 | regex_match(const charT* str, match_results<const charT*, Allocator>& m, |
| 535 | const basic_regex<charT, traits>& e, |
| 536 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 537 | |
| 538 | template <class ST, class SA, class Allocator, class charT, class traits> |
| 539 | bool |
| 540 | regex_match(const basic_string<charT, ST, SA>& s, |
| 541 | match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m, |
| 542 | const basic_regex<charT, traits>& e, |
| 543 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 544 | |
| 545 | template <class charT, class traits> |
| 546 | bool |
| 547 | regex_match(const charT* str, const basic_regex<charT, traits>& e, |
| 548 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 549 | |
| 550 | template <class ST, class SA, class charT, class traits> |
| 551 | bool |
| 552 | regex_match(const basic_string<charT, ST, SA>& s, |
| 553 | const basic_regex<charT, traits>& e, |
| 554 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 555 | |
| 556 | template <class BidirectionalIterator, class Allocator, class charT, class traits> |
| 557 | bool |
| 558 | regex_search(BidirectionalIterator first, BidirectionalIterator last, |
| 559 | match_results<BidirectionalIterator, Allocator>& m, |
| 560 | const basic_regex<charT, traits>& e, |
| 561 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 562 | |
| 563 | template <class BidirectionalIterator, class charT, class traits> |
| 564 | bool |
| 565 | regex_search(BidirectionalIterator first, BidirectionalIterator last, |
| 566 | const basic_regex<charT, traits>& e, |
| 567 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 568 | |
| 569 | template <class charT, class Allocator, class traits> |
| 570 | bool |
| 571 | regex_search(const charT* str, match_results<const charT*, Allocator>& m, |
| 572 | const basic_regex<charT, traits>& e, |
| 573 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 574 | |
| 575 | template <class charT, class traits> |
| 576 | bool |
| 577 | regex_search(const charT* str, const basic_regex<charT, traits>& e, |
| 578 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 579 | |
| 580 | template <class ST, class SA, class charT, class traits> |
| 581 | bool |
| 582 | regex_search(const basic_string<charT, ST, SA>& s, |
| 583 | const basic_regex<charT, traits>& e, |
| 584 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 585 | |
| 586 | template <class ST, class SA, class Allocator, class charT, class traits> |
| 587 | bool |
| 588 | regex_search(const basic_string<charT, ST, SA>& s, |
| 589 | match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m, |
| 590 | const basic_regex<charT, traits>& e, |
| 591 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 592 | |
| 593 | template <class OutputIterator, class BidirectionalIterator, |
| 594 | class traits, class charT, class ST, class SA> |
| 595 | OutputIterator |
| 596 | regex_replace(OutputIterator out, |
| 597 | BidirectionalIterator first, BidirectionalIterator last, |
| 598 | const basic_regex<charT, traits>& e, |
| 599 | const basic_string<charT, ST, SA>& fmt, |
| 600 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 601 | |
| 602 | template <class OutputIterator, class BidirectionalIterator, |
| 603 | class traits, class charT> |
| 604 | OutputIterator |
| 605 | regex_replace(OutputIterator out, |
| 606 | BidirectionalIterator first, BidirectionalIterator last, |
| 607 | const basic_regex<charT, traits>& e, const charT* fmt, |
| 608 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 609 | |
| 610 | template <class traits, class charT, class ST, class SA, class FST, class FSA>> |
| 611 | basic_string<charT, ST, SA> |
| 612 | regex_replace(const basic_string<charT, ST, SA>& s, |
| 613 | const basic_regex<charT, traits>& e, |
| 614 | const basic_string<charT, FST, FSA>& fmt, |
| 615 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 616 | |
| 617 | template <class traits, class charT, class ST, class SA> |
| 618 | basic_string<charT, ST, SA> |
| 619 | regex_replace(const basic_string<charT, ST, SA>& s, |
| 620 | const basic_regex<charT, traits>& e, const charT* fmt, |
| 621 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 622 | |
| 623 | template <class traits, class charT, class ST, class SA> |
| 624 | basic_string<charT> |
| 625 | regex_replace(const charT* s, |
| 626 | const basic_regex<charT, traits>& e, |
| 627 | const basic_string<charT, ST, SA>& fmt, |
| 628 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 629 | |
| 630 | template <class traits, class charT> |
| 631 | basic_string<charT> |
| 632 | regex_replace(const charT* s, |
| 633 | const basic_regex<charT, traits>& e, |
| 634 | const charT* fmt, |
| 635 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 636 | |
| 637 | template <class BidirectionalIterator, |
| 638 | class charT = typename iterator_traits< BidirectionalIterator>::value_type, |
| 639 | class traits = regex_traits<charT>> |
| 640 | class regex_iterator |
| 641 | { |
| 642 | public: |
| 643 | typedef basic_regex<charT, traits> regex_type; |
| 644 | typedef match_results<BidirectionalIterator> value_type; |
| 645 | typedef ptrdiff_t difference_type; |
| 646 | typedef const value_type* pointer; |
| 647 | typedef const value_type& reference; |
| 648 | typedef forward_iterator_tag iterator_category; |
| 649 | |
| 650 | regex_iterator(); |
| 651 | regex_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 652 | const regex_type& re, |
| 653 | regex_constants::match_flag_type m = regex_constants::match_default); |
| 654 | regex_iterator(const regex_iterator&); |
| 655 | regex_iterator& operator=(const regex_iterator&); |
| 656 | |
| 657 | bool operator==(const regex_iterator&) const; |
| 658 | bool operator!=(const regex_iterator&) const; |
| 659 | |
| 660 | const value_type& operator*() const; |
| 661 | const value_type* operator->() const; |
| 662 | |
| 663 | regex_iterator& operator++(); |
| 664 | regex_iterator operator++(int); |
| 665 | }; |
| 666 | |
| 667 | typedef regex_iterator<const char*> cregex_iterator; |
| 668 | typedef regex_iterator<const wchar_t*> wcregex_iterator; |
| 669 | typedef regex_iterator<string::const_iterator> sregex_iterator; |
| 670 | typedef regex_iterator<wstring::const_iterator> wsregex_iterator; |
| 671 | |
| 672 | template <class BidirectionalIterator, |
| 673 | class charT = typename iterator_traits< BidirectionalIterator>::value_type, |
| 674 | class traits = regex_traits<charT>> |
| 675 | class regex_token_iterator |
| 676 | { |
| 677 | public: |
| 678 | typedef basic_regex<charT, traits> regex_type; |
| 679 | typedef sub_match<BidirectionalIterator> value_type; |
| 680 | typedef ptrdiff_t difference_type; |
| 681 | typedef const value_type* pointer; |
| 682 | typedef const value_type& reference; |
| 683 | typedef forward_iterator_tag iterator_category; |
| 684 | |
| 685 | regex_token_iterator(); |
| 686 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 687 | const regex_type& re, int submatch = 0, |
| 688 | regex_constants::match_flag_type m = regex_constants::match_default); |
| 689 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 690 | const regex_type& re, const vector<int>& submatches, |
| 691 | regex_constants::match_flag_type m = regex_constants::match_default); |
| 692 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 693 | const regex_type& re, initializer_list<int> submatches, |
| 694 | regex_constants::match_flag_type m = regex_constants::match_default); |
| 695 | template <size_t N> |
| 696 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 697 | const regex_type& re, const int (&submatches)[N], |
| 698 | regex_constants::match_flag_type m = regex_constants::match_default); |
| 699 | regex_token_iterator(const regex_token_iterator&); |
| 700 | regex_token_iterator& operator=(const regex_token_iterator&); |
| 701 | |
| 702 | bool operator==(const regex_token_iterator&) const; |
| 703 | bool operator!=(const regex_token_iterator&) const; |
| 704 | |
| 705 | const value_type& operator*() const; |
| 706 | const value_type* operator->() const; |
| 707 | |
| 708 | regex_token_iterator& operator++(); |
| 709 | regex_token_iterator operator++(int); |
| 710 | }; |
| 711 | |
| 712 | typedef regex_token_iterator<const char*> cregex_token_iterator; |
| 713 | typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator; |
| 714 | typedef regex_token_iterator<string::const_iterator> sregex_token_iterator; |
| 715 | typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator; |
| 716 | |
| 717 | } // std |
| 718 | */ |
| 719 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 720 | // temporary! |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 721 | #include <sstream> |
| 722 | #include <cassert> |
| 723 | |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 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, |
| 750 | ECMAScript = 1 << 4, |
| 751 | basic = 1 << 5, |
| 752 | extended = 1 << 6, |
| 753 | awk = 1 << 7, |
| 754 | grep = 1 << 8, |
| 755 | egrep = 1 << 9 |
| 756 | }; |
| 757 | |
| 758 | inline |
| 759 | /*constexpr*/ |
| 760 | syntax_option_type |
| 761 | operator~(syntax_option_type __x) |
| 762 | { |
| 763 | return syntax_option_type(~int(__x)); |
| 764 | } |
| 765 | |
| 766 | inline |
| 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 | |
| 774 | inline |
| 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 | |
| 782 | inline |
| 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 | |
| 790 | inline |
| 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 | |
| 799 | inline |
| 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 | |
| 808 | inline |
| 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, |
| 833 | format_first_only = 1 << 10 |
| 834 | }; |
| 835 | |
| 836 | inline |
| 837 | /*constexpr*/ |
| 838 | match_flag_type |
| 839 | operator~(match_flag_type __x) |
| 840 | { |
| 841 | return match_flag_type(~int(__x)); |
| 842 | } |
| 843 | |
| 844 | inline |
| 845 | /*constexpr*/ |
| 846 | match_flag_type |
| 847 | operator&(match_flag_type __x, match_flag_type __y) |
| 848 | { |
| 849 | return match_flag_type(int(__x) & int(__y)); |
| 850 | } |
| 851 | |
| 852 | inline |
| 853 | /*constexpr*/ |
| 854 | match_flag_type |
| 855 | operator|(match_flag_type __x, match_flag_type __y) |
| 856 | { |
| 857 | return match_flag_type(int(__x) | int(__y)); |
| 858 | } |
| 859 | |
| 860 | inline |
| 861 | /*constexpr*/ |
| 862 | match_flag_type |
| 863 | operator^(match_flag_type __x, match_flag_type __y) |
| 864 | { |
| 865 | return match_flag_type(int(__x) ^ int(__y)); |
| 866 | } |
| 867 | |
| 868 | inline |
| 869 | /*constexpr*/ |
| 870 | match_flag_type& |
| 871 | operator&=(match_flag_type& __x, match_flag_type __y) |
| 872 | { |
| 873 | __x = __x & __y; |
| 874 | return __x; |
| 875 | } |
| 876 | |
| 877 | inline |
| 878 | /*constexpr*/ |
| 879 | match_flag_type& |
| 880 | operator|=(match_flag_type& __x, match_flag_type __y) |
| 881 | { |
| 882 | __x = __x | __y; |
| 883 | return __x; |
| 884 | } |
| 885 | |
| 886 | inline |
| 887 | /*constexpr*/ |
| 888 | match_flag_type& |
| 889 | operator^=(match_flag_type& __x, match_flag_type __y) |
| 890 | { |
| 891 | __x = __x ^ __y; |
| 892 | return __x; |
| 893 | } |
| 894 | |
| 895 | enum error_type |
| 896 | { |
| 897 | error_collate = 1, |
| 898 | error_ctype, |
| 899 | error_escape, |
| 900 | error_backref, |
| 901 | error_brack, |
| 902 | error_paren, |
| 903 | error_brace, |
| 904 | error_badbrace, |
| 905 | error_range, |
| 906 | error_space, |
| 907 | error_badrepeat, |
| 908 | error_complexity, |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 909 | error_stack, |
| 910 | error_temp |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 911 | }; |
| 912 | |
| 913 | } // regex_constants |
| 914 | |
| 915 | class _LIBCPP_EXCEPTION_ABI regex_error |
| 916 | : public runtime_error |
| 917 | { |
| 918 | regex_constants::error_type __code_; |
| 919 | public: |
| 920 | explicit regex_error(regex_constants::error_type __ecode); |
| 921 | virtual ~regex_error() throw(); |
| 922 | regex_constants::error_type code() const {return __code_;} |
| 923 | }; |
| 924 | |
| 925 | template <class _CharT> |
| 926 | struct regex_traits |
| 927 | { |
| 928 | public: |
| 929 | typedef _CharT char_type; |
| 930 | typedef basic_string<char_type> string_type; |
| 931 | typedef locale locale_type; |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 932 | typedef ctype_base::mask char_class_type; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 933 | |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 934 | static const char_class_type __regex_word = 0x80; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 935 | private: |
| 936 | locale __loc_; |
| 937 | const ctype<char_type>* __ct_; |
| 938 | const collate<char_type>* __col_; |
| 939 | |
| 940 | public: |
| 941 | regex_traits(); |
| 942 | |
| 943 | static size_t length(const char_type* __p) |
| 944 | {return char_traits<char_type>::length(__p);} |
| 945 | char_type translate(char_type __c) const {return __c;} |
| 946 | char_type translate_nocase(char_type __c) const; |
| 947 | template <class _ForwardIterator> |
| 948 | string_type |
| 949 | transform(_ForwardIterator __f, _ForwardIterator __l) const; |
| 950 | template <class _ForwardIterator> |
| 951 | string_type |
| 952 | transform_primary( _ForwardIterator __f, _ForwardIterator __l) const |
| 953 | {return __transform_primary(__f, __l, char_type());} |
| 954 | template <class _ForwardIterator> |
| 955 | string_type |
| 956 | lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const |
| 957 | {return __lookup_collatename(__f, __l, char_type());} |
| 958 | template <class _ForwardIterator> |
| 959 | char_class_type |
| 960 | lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 961 | bool __icase = false) const |
| 962 | {return __lookup_classname(__f, __l, __icase, char_type());} |
| 963 | bool isctype(char_type __c, char_class_type __m) const; |
| 964 | int value(char_type __ch, int __radix) const |
| 965 | {return __value(__ch, __radix);} |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 966 | locale_type imbue(locale_type __l); |
| 967 | locale_type getloc()const {return __loc_;} |
| 968 | |
| 969 | private: |
| 970 | void __init(); |
| 971 | |
| 972 | template <class _ForwardIterator> |
| 973 | string_type |
| 974 | __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const; |
| 975 | template <class _ForwardIterator> |
| 976 | string_type |
| 977 | __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; |
| 978 | |
| 979 | template <class _ForwardIterator> |
| 980 | string_type |
| 981 | __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const; |
| 982 | template <class _ForwardIterator> |
| 983 | string_type |
| 984 | __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 985 | |
| 986 | template <class _ForwardIterator> |
| 987 | char_class_type |
| 988 | __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
| 989 | bool __icase, char) const; |
| 990 | template <class _ForwardIterator> |
| 991 | char_class_type |
| 992 | __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
| 993 | bool __icase, wchar_t) const; |
| 994 | |
| 995 | static int __value(unsigned char __ch, int __radix); |
| 996 | int __value(char __ch, int __radix) const |
| 997 | {return __value(static_cast<unsigned char>(__ch), __radix);} |
| 998 | int __value(wchar_t __ch, int __radix) const; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 999 | }; |
| 1000 | |
| 1001 | template <class _CharT> |
| 1002 | regex_traits<_CharT>::regex_traits() |
| 1003 | { |
| 1004 | __init(); |
| 1005 | } |
| 1006 | |
| 1007 | template <class _CharT> |
| 1008 | typename regex_traits<_CharT>::char_type |
| 1009 | regex_traits<_CharT>::translate_nocase(char_type __c) const |
| 1010 | { |
| 1011 | return __ct_->tolower(__c); |
| 1012 | } |
| 1013 | |
| 1014 | template <class _CharT> |
| 1015 | template <class _ForwardIterator> |
| 1016 | typename regex_traits<_CharT>::string_type |
| 1017 | regex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const |
| 1018 | { |
| 1019 | string_type __s(__f, __l); |
| 1020 | return __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1021 | } |
| 1022 | |
| 1023 | template <class _CharT> |
| 1024 | void |
| 1025 | regex_traits<_CharT>::__init() |
| 1026 | { |
| 1027 | __ct_ = &use_facet<ctype<char_type> >(__loc_); |
| 1028 | __col_ = &use_facet<collate<char_type> >(__loc_); |
| 1029 | } |
| 1030 | |
| 1031 | template <class _CharT> |
| 1032 | typename regex_traits<_CharT>::locale_type |
| 1033 | regex_traits<_CharT>::imbue(locale_type __l) |
| 1034 | { |
| 1035 | locale __r = __loc_; |
| 1036 | __loc_ = __l; |
| 1037 | __init(); |
| 1038 | return __r; |
| 1039 | } |
| 1040 | |
| 1041 | // transform_primary is very FreeBSD-specific |
| 1042 | |
| 1043 | template <class _CharT> |
| 1044 | template <class _ForwardIterator> |
| 1045 | typename regex_traits<_CharT>::string_type |
| 1046 | regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, |
| 1047 | _ForwardIterator __l, char) const |
| 1048 | { |
| 1049 | const string_type __s(__f, __l); |
| 1050 | string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1051 | switch (__d.size()) |
| 1052 | { |
| 1053 | case 1: |
| 1054 | break; |
| 1055 | case 12: |
| 1056 | __d[11] = __d[3]; |
| 1057 | break; |
| 1058 | default: |
| 1059 | __d.clear(); |
| 1060 | break; |
| 1061 | } |
| 1062 | return __d; |
| 1063 | } |
| 1064 | |
| 1065 | template <class _CharT> |
| 1066 | template <class _ForwardIterator> |
| 1067 | typename regex_traits<_CharT>::string_type |
| 1068 | regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, |
| 1069 | _ForwardIterator __l, wchar_t) const |
| 1070 | { |
| 1071 | const string_type __s(__f, __l); |
| 1072 | string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1073 | switch (__d.size()) |
| 1074 | { |
| 1075 | case 1: |
| 1076 | break; |
| 1077 | case 3: |
| 1078 | __d[2] = __d[0]; |
| 1079 | break; |
| 1080 | default: |
| 1081 | __d.clear(); |
| 1082 | break; |
| 1083 | } |
| 1084 | return __d; |
| 1085 | } |
| 1086 | |
| 1087 | // lookup_collatename is very FreeBSD-specific |
| 1088 | |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1089 | string __get_collation_name(const char* __s); |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1090 | |
| 1091 | template <class _CharT> |
| 1092 | template <class _ForwardIterator> |
| 1093 | typename regex_traits<_CharT>::string_type |
| 1094 | regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, |
| 1095 | _ForwardIterator __l, char) const |
| 1096 | { |
| 1097 | string_type __s(__f, __l); |
| 1098 | string_type __r; |
| 1099 | if (!__s.empty()) |
| 1100 | { |
| 1101 | __r = __get_collation_name(__s.c_str()); |
| 1102 | if (__r.empty() && __s.size() <= 2) |
| 1103 | { |
| 1104 | __r = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1105 | if (__r.size() == 1 || __r.size() == 12) |
| 1106 | __r = __s; |
| 1107 | else |
| 1108 | __r.clear(); |
| 1109 | } |
| 1110 | } |
| 1111 | return __r; |
| 1112 | } |
| 1113 | |
| 1114 | template <class _CharT> |
| 1115 | template <class _ForwardIterator> |
| 1116 | typename regex_traits<_CharT>::string_type |
| 1117 | regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, |
| 1118 | _ForwardIterator __l, wchar_t) const |
| 1119 | { |
| 1120 | string_type __s(__f, __l); |
| 1121 | string __n; |
| 1122 | __n.reserve(__s.size()); |
| 1123 | for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); |
| 1124 | __i != __e; ++__i) |
| 1125 | { |
| 1126 | if (static_cast<unsigned>(*__i) >= 127) |
| 1127 | return string_type(); |
| 1128 | __n.push_back(char(*__i)); |
| 1129 | } |
| 1130 | string_type __r; |
| 1131 | if (!__s.empty()) |
| 1132 | { |
| 1133 | __n = __get_collation_name(__n.c_str()); |
| 1134 | if (!__n.empty()) |
| 1135 | __r.assign(__n.begin(), __n.end()); |
| 1136 | else if (__s.size() <= 2) |
| 1137 | { |
| 1138 | __r = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1139 | if (__r.size() == 1 || __r.size() == 3) |
| 1140 | __r = __s; |
| 1141 | else |
| 1142 | __r.clear(); |
| 1143 | } |
| 1144 | } |
| 1145 | return __r; |
| 1146 | } |
| 1147 | |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1148 | // lookup_classname |
| 1149 | |
| 1150 | ctype_base::mask __get_classname(const char* __s, bool __icase); |
| 1151 | |
| 1152 | template <class _CharT> |
| 1153 | template <class _ForwardIterator> |
| 1154 | typename regex_traits<_CharT>::char_class_type |
| 1155 | regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, |
| 1156 | _ForwardIterator __l, |
| 1157 | bool __icase, char) const |
| 1158 | { |
| 1159 | string_type __s(__f, __l); |
| 1160 | __ct_->tolower(&__s[0], &__s[0] + __s.size()); |
| 1161 | return __get_classname(__s.c_str(), __icase); |
| 1162 | } |
| 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, wchar_t) const |
| 1170 | { |
| 1171 | string_type __s(__f, __l); |
| 1172 | __ct_->tolower(&__s[0], &__s[0] + __s.size()); |
| 1173 | string __n; |
| 1174 | __n.reserve(__s.size()); |
| 1175 | for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); |
| 1176 | __i != __e; ++__i) |
| 1177 | { |
| 1178 | if (static_cast<unsigned>(*__i) >= 127) |
| 1179 | return char_class_type(); |
| 1180 | __n.push_back(char(*__i)); |
| 1181 | } |
| 1182 | return __get_classname(__n.c_str(), __icase); |
| 1183 | } |
| 1184 | |
| 1185 | template <class _CharT> |
| 1186 | bool |
| 1187 | regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const |
| 1188 | { |
| 1189 | if (__ct_->is(__m, __c)) |
| 1190 | return true; |
| 1191 | return (__c == '_' && (__m & __regex_word)); |
| 1192 | } |
| 1193 | |
| 1194 | template <class _CharT> |
| 1195 | int |
| 1196 | regex_traits<_CharT>::__value(unsigned char __ch, int __radix) |
| 1197 | { |
| 1198 | if ((__ch & 0xF8u) == 0x30) // '0' <= __ch && __ch <= '7' |
| 1199 | return __ch - '0'; |
| 1200 | if (__radix != 8) |
| 1201 | { |
| 1202 | if ((__ch & 0xFEu) == 0x38) // '8' <= __ch && __ch <= '9' |
| 1203 | return __ch - '0'; |
| 1204 | if (__radix == 16) |
| 1205 | { |
| 1206 | __ch |= 0x20; // tolower |
| 1207 | if ('a' <= __ch && __ch <= 'f') |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 1208 | return __ch - ('a' - 10); |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1209 | } |
| 1210 | } |
| 1211 | return -1; |
| 1212 | } |
| 1213 | |
| 1214 | template <class _CharT> |
| 1215 | inline |
| 1216 | int |
| 1217 | regex_traits<_CharT>::__value(wchar_t __ch, int __radix) const |
| 1218 | { |
| 1219 | return __value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix); |
| 1220 | } |
| 1221 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1222 | template <class _CharT> class __node; |
| 1223 | |
| 1224 | template <class _BidirectionalIterator> class sub_match; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1225 | |
| 1226 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1227 | struct __state |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1228 | { |
| 1229 | enum |
| 1230 | { |
| 1231 | __end_state = -1000, |
| 1232 | __consume_input, // -999 |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1233 | __begin_marked_expr, // -998 |
| 1234 | __end_marked_expr, // -997 |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1235 | __pop_state, // -996 |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1236 | __accept_and_consume, // -995 |
| 1237 | __accept_but_not_consume, // -994 |
| 1238 | __reject, // -993 |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1239 | __split, |
| 1240 | __repeat |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1241 | }; |
| 1242 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1243 | int __do_; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1244 | const _CharT* __first_; |
| 1245 | const _CharT* __current_; |
| 1246 | const _CharT* __last_; |
| 1247 | vector<sub_match<const _CharT*> > __sub_matches_; |
| 1248 | vector<pair<size_t, const _CharT*> > __loop_data_; |
| 1249 | const __node<_CharT>* __node_; |
| 1250 | regex_constants::match_flag_type __flags_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1251 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1252 | __state() |
| 1253 | : __do_(0), __first_(nullptr), __current_(nullptr), __last_(nullptr), |
| 1254 | __node_(nullptr), __flags_() {} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1255 | }; |
| 1256 | |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1257 | template <class _CharT> |
| 1258 | ostream& |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1259 | operator<<(ostream& os, const __state<_CharT>& c) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1260 | { |
| 1261 | os << c.__do_; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1262 | if (c.__node_) |
| 1263 | os << ", " << c.__node_->speak(); |
| 1264 | else |
| 1265 | os << ", null"; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1266 | return os; |
| 1267 | } |
| 1268 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1269 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1270 | // __node |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1271 | |
| 1272 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1273 | class __node |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1274 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1275 | __node(const __node&); |
| 1276 | __node& operator=(const __node&); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1277 | public: |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1278 | typedef _STD::__state<_CharT> __state; |
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() {} |
| 1281 | virtual ~__node() {} |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1282 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1283 | virtual void __exec(__state&) const {}; |
| 1284 | virtual void __exec_split(bool, __state&) const {}; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1285 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1286 | virtual string speak() const {return "__node";} |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1287 | }; |
| 1288 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1289 | // __end_state |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1290 | |
| 1291 | template <class _CharT> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1292 | class __end_state |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1293 | : public __node<_CharT> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1294 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1295 | public: |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1296 | typedef _STD::__state<_CharT> __state; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1297 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1298 | __end_state() {} |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1299 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1300 | virtual void __exec(__state&) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1301 | |
| 1302 | virtual string speak() const {return "end state";} |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1303 | }; |
| 1304 | |
| 1305 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1306 | void |
| 1307 | __end_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1308 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1309 | __s.__do_ = __state::__end_state; |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1310 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1311 | |
| 1312 | // __has_one_state |
| 1313 | |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1314 | template <class _CharT> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1315 | class __has_one_state |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1316 | : public __node<_CharT> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1317 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1318 | __node<_CharT>* __first_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1319 | |
| 1320 | public: |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1321 | explicit __has_one_state(__node<_CharT>* __s) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1322 | : __first_(__s) {} |
| 1323 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1324 | __node<_CharT>* first() const {return __first_;} |
| 1325 | __node<_CharT>*& first() {return __first_;} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1326 | }; |
| 1327 | |
| 1328 | // __owns_one_state |
| 1329 | |
| 1330 | template <class _CharT> |
| 1331 | class __owns_one_state |
| 1332 | : public __has_one_state<_CharT> |
| 1333 | { |
| 1334 | typedef __has_one_state<_CharT> base; |
| 1335 | |
| 1336 | public: |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1337 | explicit __owns_one_state(__node<_CharT>* __s) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1338 | : base(__s) {} |
| 1339 | |
| 1340 | virtual ~__owns_one_state(); |
| 1341 | }; |
| 1342 | |
| 1343 | template <class _CharT> |
| 1344 | __owns_one_state<_CharT>::~__owns_one_state() |
| 1345 | { |
| 1346 | delete this->first(); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1347 | } |
| 1348 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1349 | // __empty_state |
| 1350 | |
| 1351 | template <class _CharT> |
| 1352 | class __empty_state |
| 1353 | : public __owns_one_state<_CharT> |
| 1354 | { |
| 1355 | typedef __owns_one_state<_CharT> base; |
| 1356 | |
| 1357 | public: |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1358 | typedef _STD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1359 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1360 | explicit __empty_state(__node<_CharT>* __s) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1361 | : base(__s) {} |
| 1362 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1363 | virtual void __exec(__state&) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1364 | |
| 1365 | virtual string speak() const {return "empty state";} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1366 | }; |
| 1367 | |
| 1368 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1369 | void |
| 1370 | __empty_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1371 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1372 | __s.__do_ = __state::__accept_but_not_consume; |
| 1373 | __s.__node_ = this->first(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | // __empty_non_own_state |
| 1377 | |
| 1378 | template <class _CharT> |
| 1379 | class __empty_non_own_state |
| 1380 | : public __has_one_state<_CharT> |
| 1381 | { |
| 1382 | typedef __has_one_state<_CharT> base; |
| 1383 | |
| 1384 | public: |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1385 | typedef _STD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1386 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1387 | explicit __empty_non_own_state(__node<_CharT>* __s) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1388 | : base(__s) {} |
| 1389 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1390 | virtual void __exec(__state&) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1391 | |
| 1392 | virtual string speak() const {return "empty non-owning state";} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1393 | }; |
| 1394 | |
| 1395 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1396 | void |
| 1397 | __empty_non_own_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1398 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1399 | __s.__do_ = __state::__accept_but_not_consume; |
| 1400 | __s.__node_ = this->first(); |
| 1401 | } |
| 1402 | |
| 1403 | // __repeat_one_loop |
| 1404 | |
| 1405 | template <class _CharT> |
| 1406 | class __repeat_one_loop |
| 1407 | : public __has_one_state<_CharT> |
| 1408 | { |
| 1409 | typedef __has_one_state<_CharT> base; |
| 1410 | |
| 1411 | public: |
| 1412 | typedef _STD::__state<_CharT> __state; |
| 1413 | |
| 1414 | explicit __repeat_one_loop(__node<_CharT>* __s) |
| 1415 | : base(__s) {} |
| 1416 | |
| 1417 | virtual void __exec(__state&) const; |
| 1418 | |
| 1419 | virtual string speak() const {return "repeat loop";} |
| 1420 | }; |
| 1421 | |
| 1422 | template <class _CharT> |
| 1423 | void |
| 1424 | __repeat_one_loop<_CharT>::__exec(__state& __s) const |
| 1425 | { |
| 1426 | __s.__do_ = __state::__repeat; |
| 1427 | __s.__node_ = this->first(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | // __owns_two_states |
| 1431 | |
| 1432 | template <class _CharT> |
| 1433 | class __owns_two_states |
| 1434 | : public __owns_one_state<_CharT> |
| 1435 | { |
| 1436 | typedef __owns_one_state<_CharT> base; |
| 1437 | |
| 1438 | base* __second_; |
| 1439 | |
| 1440 | public: |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1441 | explicit __owns_two_states(__node<_CharT>* __s1, base* __s2) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1442 | : base(__s1), __second_(__s2) {} |
| 1443 | |
| 1444 | virtual ~__owns_two_states(); |
| 1445 | |
| 1446 | base* second() const {return __second_;} |
| 1447 | base*& second() {return __second_;} |
| 1448 | }; |
| 1449 | |
| 1450 | template <class _CharT> |
| 1451 | __owns_two_states<_CharT>::~__owns_two_states() |
| 1452 | { |
| 1453 | delete __second_; |
| 1454 | } |
| 1455 | |
| 1456 | // __loop |
| 1457 | |
| 1458 | template <class _CharT> |
| 1459 | class __loop |
| 1460 | : public __owns_two_states<_CharT> |
| 1461 | { |
| 1462 | typedef __owns_two_states<_CharT> base; |
| 1463 | |
| 1464 | size_t __min_; |
| 1465 | size_t __max_; |
| 1466 | unsigned __loop_id_; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1467 | unsigned __mexp_begin_; |
| 1468 | unsigned __mexp_end_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1469 | bool __greedy_; |
| 1470 | |
| 1471 | public: |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1472 | typedef _STD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1473 | |
| 1474 | explicit __loop(unsigned __loop_id, |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1475 | __node<_CharT>* __s1, __owns_one_state<_CharT>* __s2, |
| 1476 | unsigned __mexp_begin, unsigned __mexp_end, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1477 | bool __greedy = true, |
| 1478 | size_t __min = 0, |
| 1479 | size_t __max = numeric_limits<size_t>::max()) |
| 1480 | : base(__s1, __s2), __min_(__min), __max_(__max), __loop_id_(__loop_id), |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1481 | __mexp_begin_(__mexp_begin), __mexp_end_(__mexp_end), |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1482 | __greedy_(__greedy) {} |
| 1483 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1484 | virtual void __exec(__state& __s) const; |
| 1485 | virtual void __exec_split(bool __second, __state& __s) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1486 | |
| 1487 | virtual string speak() const |
| 1488 | { |
| 1489 | ostringstream os; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1490 | os << "loop "<< __loop_id_ << " {" << __min_ << ',' << __max_ << "}"; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1491 | if (!__greedy_) |
| 1492 | os << " not"; |
| 1493 | os << " greedy"; |
| 1494 | return os.str(); |
| 1495 | } |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1496 | |
| 1497 | private: |
| 1498 | void __init_repeat(__state& __s) const |
| 1499 | { |
| 1500 | __s.__loop_data_[__loop_id_].second = __s.__current_; |
| 1501 | for (size_t __i = __mexp_begin_-1; __i != __mexp_end_-1; ++__i) |
| 1502 | { |
| 1503 | __s.__sub_matches_[__i].first = __s.__last_; |
| 1504 | __s.__sub_matches_[__i].second = __s.__last_; |
| 1505 | __s.__sub_matches_[__i].matched = false; |
| 1506 | } |
| 1507 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1508 | }; |
| 1509 | |
| 1510 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1511 | void |
| 1512 | __loop<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1513 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1514 | if (__s.__do_ == __state::__repeat) |
| 1515 | { |
| 1516 | bool __do_repeat = ++__s.__loop_data_[__loop_id_].first < __max_; |
| 1517 | bool __do_alt = __s.__loop_data_[__loop_id_].first >= __min_; |
| 1518 | if (__do_repeat && __do_alt && |
| 1519 | __s.__loop_data_[__loop_id_].second == __s.__current_) |
| 1520 | __do_repeat = false; |
| 1521 | if (__do_repeat && __do_alt) |
| 1522 | __s.__do_ = __state::__split; |
| 1523 | else if (__do_repeat) |
| 1524 | { |
| 1525 | __s.__do_ = __state::__accept_but_not_consume; |
| 1526 | __s.__node_ = this->first(); |
| 1527 | __init_repeat(__s); |
| 1528 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1529 | else |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1530 | { |
| 1531 | __s.__do_ = __state::__accept_but_not_consume; |
| 1532 | __s.__node_ = this->second(); |
| 1533 | } |
| 1534 | } |
| 1535 | else |
| 1536 | { |
| 1537 | if (__max_ > 0) |
| 1538 | __s.__do_ = __state::__split; |
| 1539 | else |
| 1540 | { |
| 1541 | __s.__do_ = __state::__accept_but_not_consume; |
| 1542 | __s.__node_ = this->second(); |
| 1543 | } |
| 1544 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1545 | } |
| 1546 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1547 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1548 | void |
| 1549 | __loop<_CharT>::__exec_split(bool __second, __state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1550 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1551 | __s.__do_ = __state::__accept_but_not_consume; |
| 1552 | if (__greedy_ != __second) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1553 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1554 | __s.__node_ = this->first(); |
| 1555 | __init_repeat(__s); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1556 | } |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1557 | else |
| 1558 | __s.__node_ = this->second(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1559 | } |
| 1560 | |
| 1561 | // __begin_marked_subexpression |
| 1562 | |
| 1563 | template <class _CharT> |
| 1564 | class __begin_marked_subexpression |
| 1565 | : public __owns_one_state<_CharT> |
| 1566 | { |
| 1567 | typedef __owns_one_state<_CharT> base; |
| 1568 | |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1569 | unsigned __mexp_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1570 | public: |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1571 | typedef _STD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1572 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1573 | explicit __begin_marked_subexpression(unsigned __mexp, __node<_CharT>* __s) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1574 | : base(__s), __mexp_(__mexp) {} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1575 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1576 | virtual void __exec(__state&) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1577 | |
| 1578 | virtual string speak() const |
| 1579 | { |
| 1580 | ostringstream os; |
| 1581 | os << "begin marked expr " << __mexp_; |
| 1582 | return os.str(); |
| 1583 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1584 | }; |
| 1585 | |
| 1586 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1587 | void |
| 1588 | __begin_marked_subexpression<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1589 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1590 | __s.__do_ = __state::__accept_but_not_consume; |
| 1591 | __s.__sub_matches_[__mexp_-1].first = __s.__current_; |
| 1592 | __s.__node_ = this->first(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1593 | } |
| 1594 | |
| 1595 | // __end_marked_subexpression |
| 1596 | |
| 1597 | template <class _CharT> |
| 1598 | class __end_marked_subexpression |
| 1599 | : public __owns_one_state<_CharT> |
| 1600 | { |
| 1601 | typedef __owns_one_state<_CharT> base; |
| 1602 | |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1603 | unsigned __mexp_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1604 | public: |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1605 | typedef _STD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1606 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1607 | explicit __end_marked_subexpression(unsigned __mexp, __node<_CharT>* __s) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1608 | : base(__s), __mexp_(__mexp) {} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1609 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1610 | virtual void __exec(__state&) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1611 | |
| 1612 | virtual string speak() const |
| 1613 | { |
| 1614 | ostringstream os; |
| 1615 | os << "end marked expr " << __mexp_; |
| 1616 | return os.str(); |
| 1617 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1618 | }; |
| 1619 | |
| 1620 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1621 | void |
| 1622 | __end_marked_subexpression<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1623 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1624 | __s.__do_ = __state::__accept_but_not_consume; |
| 1625 | __s.__sub_matches_[__mexp_-1].second = __s.__current_; |
| 1626 | __s.__sub_matches_[__mexp_-1].matched = true; |
| 1627 | __s.__node_ = this->first(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1628 | } |
| 1629 | |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1630 | // __back_ref |
| 1631 | |
| 1632 | template <class _CharT> |
| 1633 | class __back_ref |
| 1634 | : public __owns_one_state<_CharT> |
| 1635 | { |
| 1636 | typedef __owns_one_state<_CharT> base; |
| 1637 | |
| 1638 | unsigned __mexp_; |
| 1639 | public: |
| 1640 | typedef _STD::__state<_CharT> __state; |
| 1641 | |
| 1642 | explicit __back_ref(unsigned __mexp, __node<_CharT>* __s) |
| 1643 | : base(__s), __mexp_(__mexp) {} |
| 1644 | |
| 1645 | virtual void __exec(__state&) const; |
| 1646 | |
| 1647 | virtual string speak() const |
| 1648 | { |
| 1649 | ostringstream os; |
| 1650 | os << "__back_ref " << __mexp_; |
| 1651 | return os.str(); |
| 1652 | } |
| 1653 | }; |
| 1654 | |
| 1655 | template <class _CharT> |
| 1656 | void |
| 1657 | __back_ref<_CharT>::__exec(__state& __s) const |
| 1658 | { |
| 1659 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1660 | if (__sm.matched) |
| 1661 | { |
| 1662 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1663 | if (__s.__last_ - __s.__current_ >= __len && |
| 1664 | _STD::equal(__sm.first, __sm.second, __s.__current_)) |
| 1665 | { |
| 1666 | __s.__do_ = __state::__accept_but_not_consume; |
| 1667 | __s.__current_ += __len; |
| 1668 | __s.__node_ = this->first(); |
| 1669 | } |
| 1670 | else |
| 1671 | { |
| 1672 | __s.__do_ = __state::__reject; |
| 1673 | __s.__node_ = nullptr; |
| 1674 | } |
| 1675 | } |
| 1676 | else |
| 1677 | { |
| 1678 | __s.__do_ = __state::__reject; |
| 1679 | __s.__node_ = nullptr; |
| 1680 | } |
| 1681 | } |
| 1682 | |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1683 | // __back_ref_icase |
| 1684 | |
| 1685 | template <class _CharT, class _Traits> |
| 1686 | class __back_ref_icase |
| 1687 | : public __owns_one_state<_CharT> |
| 1688 | { |
| 1689 | typedef __owns_one_state<_CharT> base; |
| 1690 | |
| 1691 | _Traits __traits_; |
| 1692 | unsigned __mexp_; |
| 1693 | public: |
| 1694 | typedef _STD::__state<_CharT> __state; |
| 1695 | |
| 1696 | explicit __back_ref_icase(const _Traits& __traits, unsigned __mexp, |
| 1697 | __node<_CharT>* __s) |
| 1698 | : base(__s), __traits_(__traits), __mexp_(__mexp) {} |
| 1699 | |
| 1700 | virtual void __exec(__state&) const; |
| 1701 | |
| 1702 | virtual string speak() const |
| 1703 | { |
| 1704 | ostringstream os; |
| 1705 | os << "__back_ref_icase " << __mexp_; |
| 1706 | return os.str(); |
| 1707 | } |
| 1708 | }; |
| 1709 | |
| 1710 | template <class _CharT, class _Traits> |
| 1711 | void |
| 1712 | __back_ref_icase<_CharT, _Traits>::__exec(__state& __s) const |
| 1713 | { |
| 1714 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1715 | if (__sm.matched) |
| 1716 | { |
| 1717 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1718 | if (__s.__last_ - __s.__current_ >= __len) |
| 1719 | { |
| 1720 | for (ptrdiff_t __i = 0; __i < __len; ++__i) |
| 1721 | { |
| 1722 | if (__traits_.translate_nocase(__sm.first[__i]) != |
| 1723 | __traits_.translate_nocase(__s.__current_[__i])) |
| 1724 | goto __not_equal; |
| 1725 | } |
| 1726 | __s.__do_ = __state::__accept_but_not_consume; |
| 1727 | __s.__current_ += __len; |
| 1728 | __s.__node_ = this->first(); |
| 1729 | } |
| 1730 | else |
| 1731 | { |
| 1732 | __s.__do_ = __state::__reject; |
| 1733 | __s.__node_ = nullptr; |
| 1734 | } |
| 1735 | } |
| 1736 | else |
| 1737 | { |
| 1738 | __not_equal: |
| 1739 | __s.__do_ = __state::__reject; |
| 1740 | __s.__node_ = nullptr; |
| 1741 | } |
| 1742 | } |
| 1743 | |
| 1744 | // __back_ref_collate |
| 1745 | |
| 1746 | template <class _CharT, class _Traits> |
| 1747 | class __back_ref_collate |
| 1748 | : public __owns_one_state<_CharT> |
| 1749 | { |
| 1750 | typedef __owns_one_state<_CharT> base; |
| 1751 | |
| 1752 | _Traits __traits_; |
| 1753 | unsigned __mexp_; |
| 1754 | public: |
| 1755 | typedef _STD::__state<_CharT> __state; |
| 1756 | |
| 1757 | explicit __back_ref_collate(const _Traits& __traits, unsigned __mexp, |
| 1758 | __node<_CharT>* __s) |
| 1759 | : base(__s), __traits_(__traits), __mexp_(__mexp) {} |
| 1760 | |
| 1761 | virtual void __exec(__state&) const; |
| 1762 | |
| 1763 | virtual string speak() const |
| 1764 | { |
| 1765 | ostringstream os; |
| 1766 | os << "__back_ref_collate " << __mexp_; |
| 1767 | return os.str(); |
| 1768 | } |
| 1769 | }; |
| 1770 | |
| 1771 | template <class _CharT, class _Traits> |
| 1772 | void |
| 1773 | __back_ref_collate<_CharT, _Traits>::__exec(__state& __s) const |
| 1774 | { |
| 1775 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1776 | if (__sm.matched) |
| 1777 | { |
| 1778 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1779 | if (__s.__last_ - __s.__current_ >= __len) |
| 1780 | { |
| 1781 | for (ptrdiff_t __i = 0; __i < __len; ++__i) |
| 1782 | { |
| 1783 | if (__traits_.translate(__sm.first[__i]) != |
| 1784 | __traits_.translate(__s.__current_[__i])) |
| 1785 | goto __not_equal; |
| 1786 | } |
| 1787 | __s.__do_ = __state::__accept_but_not_consume; |
| 1788 | __s.__current_ += __len; |
| 1789 | __s.__node_ = this->first(); |
| 1790 | } |
| 1791 | else |
| 1792 | { |
| 1793 | __s.__do_ = __state::__reject; |
| 1794 | __s.__node_ = nullptr; |
| 1795 | } |
| 1796 | } |
| 1797 | else |
| 1798 | { |
| 1799 | __not_equal: |
| 1800 | __s.__do_ = __state::__reject; |
| 1801 | __s.__node_ = nullptr; |
| 1802 | } |
| 1803 | } |
| 1804 | |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 1805 | // __r_anchor |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1806 | |
| 1807 | template <class _CharT> |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 1808 | class __r_anchor |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1809 | : public __owns_one_state<_CharT> |
| 1810 | { |
| 1811 | typedef __owns_one_state<_CharT> base; |
| 1812 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1813 | public: |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1814 | typedef _STD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1815 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1816 | __r_anchor(__node<_CharT>* __s) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 1817 | : base(__s) {} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1818 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1819 | virtual void __exec(__state&) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1820 | |
| 1821 | virtual string speak() const |
| 1822 | { |
| 1823 | ostringstream os; |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 1824 | os << "right anchor"; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1825 | return os.str(); |
| 1826 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1827 | }; |
| 1828 | |
| 1829 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1830 | void |
| 1831 | __r_anchor<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1832 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1833 | if (__s.__current_ == __s.__last_) |
| 1834 | { |
| 1835 | __s.__do_ = __state::__accept_but_not_consume; |
| 1836 | __s.__node_ = this->first(); |
| 1837 | } |
| 1838 | else |
| 1839 | { |
| 1840 | __s.__do_ = __state::__reject; |
| 1841 | __s.__node_ = nullptr; |
| 1842 | } |
| 1843 | } |
| 1844 | |
| 1845 | // __match_any |
| 1846 | |
| 1847 | template <class _CharT> |
| 1848 | class __match_any |
| 1849 | : public __owns_one_state<_CharT> |
| 1850 | { |
| 1851 | typedef __owns_one_state<_CharT> base; |
| 1852 | |
| 1853 | public: |
| 1854 | typedef _STD::__state<_CharT> __state; |
| 1855 | |
| 1856 | __match_any(__node<_CharT>* __s) |
| 1857 | : base(__s) {} |
| 1858 | |
| 1859 | virtual void __exec(__state&) const; |
| 1860 | |
| 1861 | virtual string speak() const |
| 1862 | { |
| 1863 | ostringstream os; |
| 1864 | os << "match any"; |
| 1865 | return os.str(); |
| 1866 | } |
| 1867 | }; |
| 1868 | |
| 1869 | template <class _CharT> |
| 1870 | void |
| 1871 | __match_any<_CharT>::__exec(__state& __s) const |
| 1872 | { |
| 1873 | if (__s.__current_ != __s.__last_ && *__s.__current_ != 0) |
| 1874 | { |
| 1875 | __s.__do_ = __state::__accept_and_consume; |
| 1876 | ++__s.__current_; |
| 1877 | __s.__node_ = this->first(); |
| 1878 | } |
| 1879 | else |
| 1880 | { |
| 1881 | __s.__do_ = __state::__reject; |
| 1882 | __s.__node_ = nullptr; |
| 1883 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1884 | } |
| 1885 | |
| 1886 | // __match_char |
| 1887 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1888 | template <class _CharT> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1889 | class __match_char |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1890 | : public __owns_one_state<_CharT> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1891 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1892 | typedef __owns_one_state<_CharT> base; |
| 1893 | |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1894 | _CharT __c_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1895 | |
| 1896 | __match_char(const __match_char&); |
| 1897 | __match_char& operator=(const __match_char&); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1898 | public: |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1899 | typedef _STD::__state<_CharT> __state; |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1900 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1901 | __match_char(_CharT __c, __node<_CharT>* __s) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1902 | : base(__s), __c_(__c) {} |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1903 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1904 | virtual void __exec(__state&) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1905 | |
| 1906 | virtual string speak() const |
| 1907 | { |
| 1908 | ostringstream os; |
| 1909 | os << "match char " << __c_; |
| 1910 | return os.str(); |
| 1911 | } |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1912 | }; |
| 1913 | |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1914 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1915 | void |
| 1916 | __match_char<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1917 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1918 | if (__s.__current_ != __s.__last_ && *__s.__current_ == __c_) |
| 1919 | { |
| 1920 | __s.__do_ = __state::__accept_and_consume; |
| 1921 | ++__s.__current_; |
| 1922 | __s.__node_ = this->first(); |
| 1923 | } |
| 1924 | else |
| 1925 | { |
| 1926 | __s.__do_ = __state::__reject; |
| 1927 | __s.__node_ = nullptr; |
| 1928 | } |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1929 | } |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1930 | |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1931 | // __match_char_icase |
| 1932 | |
| 1933 | template <class _CharT, class _Traits> |
| 1934 | class __match_char_icase |
| 1935 | : public __owns_one_state<_CharT> |
| 1936 | { |
| 1937 | typedef __owns_one_state<_CharT> base; |
| 1938 | |
| 1939 | _Traits __traits_; |
| 1940 | _CharT __c_; |
| 1941 | |
| 1942 | __match_char_icase(const __match_char_icase&); |
| 1943 | __match_char_icase& operator=(const __match_char_icase&); |
| 1944 | public: |
| 1945 | typedef _STD::__state<_CharT> __state; |
| 1946 | |
| 1947 | __match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s) |
| 1948 | : base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {} |
| 1949 | |
| 1950 | virtual void __exec(__state&) const; |
| 1951 | |
| 1952 | virtual string speak() const |
| 1953 | { |
| 1954 | ostringstream os; |
| 1955 | os << "match char icase " << __c_; |
| 1956 | return os.str(); |
| 1957 | } |
| 1958 | }; |
| 1959 | |
| 1960 | template <class _CharT, class _Traits> |
| 1961 | void |
| 1962 | __match_char_icase<_CharT, _Traits>::__exec(__state& __s) const |
| 1963 | { |
| 1964 | if (__s.__current_ != __s.__last_ && |
| 1965 | __traits_.translate_nocase(*__s.__current_) == __c_) |
| 1966 | { |
| 1967 | __s.__do_ = __state::__accept_and_consume; |
| 1968 | ++__s.__current_; |
| 1969 | __s.__node_ = this->first(); |
| 1970 | } |
| 1971 | else |
| 1972 | { |
| 1973 | __s.__do_ = __state::__reject; |
| 1974 | __s.__node_ = nullptr; |
| 1975 | } |
| 1976 | } |
| 1977 | |
| 1978 | // __match_char_collate |
| 1979 | |
| 1980 | template <class _CharT, class _Traits> |
| 1981 | class __match_char_collate |
| 1982 | : public __owns_one_state<_CharT> |
| 1983 | { |
| 1984 | typedef __owns_one_state<_CharT> base; |
| 1985 | |
| 1986 | _Traits __traits_; |
| 1987 | _CharT __c_; |
| 1988 | |
| 1989 | __match_char_collate(const __match_char_collate&); |
| 1990 | __match_char_collate& operator=(const __match_char_collate&); |
| 1991 | public: |
| 1992 | typedef _STD::__state<_CharT> __state; |
| 1993 | |
| 1994 | __match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s) |
| 1995 | : base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {} |
| 1996 | |
| 1997 | virtual void __exec(__state&) const; |
| 1998 | |
| 1999 | virtual string speak() const |
| 2000 | { |
| 2001 | ostringstream os; |
| 2002 | os << "match char icase " << __c_; |
| 2003 | return os.str(); |
| 2004 | } |
| 2005 | }; |
| 2006 | |
| 2007 | template <class _CharT, class _Traits> |
| 2008 | void |
| 2009 | __match_char_collate<_CharT, _Traits>::__exec(__state& __s) const |
| 2010 | { |
| 2011 | if (__s.__current_ != __s.__last_ && |
| 2012 | __traits_.translate(*__s.__current_) == __c_) |
| 2013 | { |
| 2014 | __s.__do_ = __state::__accept_and_consume; |
| 2015 | ++__s.__current_; |
| 2016 | __s.__node_ = this->first(); |
| 2017 | } |
| 2018 | else |
| 2019 | { |
| 2020 | __s.__do_ = __state::__reject; |
| 2021 | __s.__node_ = nullptr; |
| 2022 | } |
| 2023 | } |
| 2024 | |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2025 | // __bracket_expression |
| 2026 | |
| 2027 | template <class _CharT, class _Traits> |
| 2028 | class __bracket_expression |
| 2029 | : public __owns_one_state<_CharT> |
| 2030 | { |
| 2031 | typedef __owns_one_state<_CharT> base; |
| 2032 | typedef typename _Traits::string_type string_type; |
| 2033 | |
| 2034 | _Traits __traits_; |
| 2035 | vector<_CharT> __chars_; |
| 2036 | vector<pair<string_type, string_type> > __ranges_; |
| 2037 | vector<pair<_CharT, _CharT> > __digraphs_; |
| 2038 | vector<string_type> __equivalences_; |
| 2039 | ctype_base::mask __mask_; |
| 2040 | bool __negate_; |
| 2041 | bool __icase_; |
| 2042 | bool __collate_; |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2043 | bool __might_have_digraph_; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2044 | |
| 2045 | __bracket_expression(const __bracket_expression&); |
| 2046 | __bracket_expression& operator=(const __bracket_expression&); |
| 2047 | public: |
| 2048 | typedef _STD::__state<_CharT> __state; |
| 2049 | |
| 2050 | __bracket_expression(const _Traits& __traits, __node<_CharT>* __s, |
| 2051 | bool __negate, bool __icase, bool __collate) |
| 2052 | : base(__s), __traits_(__traits), __mask_(), __negate_(__negate), |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2053 | __icase_(__icase), __collate_(__collate), |
| 2054 | __might_have_digraph_(__traits_.getloc().name() != "C") {} |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2055 | |
| 2056 | virtual void __exec(__state&) const; |
| 2057 | |
| 2058 | void __add_char(_CharT __c) |
| 2059 | { |
| 2060 | if (__icase_) |
| 2061 | __chars_.push_back(__traits_.translate_nocase(__c)); |
| 2062 | else if (__collate_) |
| 2063 | __chars_.push_back(__traits_.translate(__c)); |
| 2064 | else |
| 2065 | __chars_.push_back(__c); |
| 2066 | } |
| 2067 | void __add_range(string_type __b, string_type __e) |
| 2068 | { |
| 2069 | if (__collate_) |
| 2070 | { |
| 2071 | if (__icase_) |
| 2072 | { |
| 2073 | for (size_t __i = 0; __i < __b.size(); ++__i) |
| 2074 | __b[__i] = __traits_.translate_nocase(__b[__i]); |
| 2075 | for (size_t __i = 0; __i < __e.size(); ++__i) |
| 2076 | __e[__i] = __traits_.translate_nocase(__e[__i]); |
| 2077 | } |
| 2078 | else |
| 2079 | { |
| 2080 | for (size_t __i = 0; __i < __b.size(); ++__i) |
| 2081 | __b[__i] = __traits_.translate(__b[__i]); |
| 2082 | for (size_t __i = 0; __i < __e.size(); ++__i) |
| 2083 | __e[__i] = __traits_.translate(__e[__i]); |
| 2084 | } |
| 2085 | __ranges_.push_back(make_pair( |
| 2086 | __traits_.transform(__b.begin(), __b.end()), |
| 2087 | __traits_.transform(__e.begin(), __e.end()))); |
| 2088 | } |
| 2089 | else |
| 2090 | { |
| 2091 | if (__b.size() != 1 || __e.size() != 1) |
| 2092 | throw regex_error(regex_constants::error_collate); |
| 2093 | if (__icase_) |
| 2094 | { |
| 2095 | __b[0] = __traits_.translate_nocase(__b[0]); |
| 2096 | __e[0] = __traits_.translate_nocase(__e[0]); |
| 2097 | } |
| 2098 | __ranges_.push_back(make_pair(_STD::move(__b), _STD::move(__e))); |
| 2099 | } |
| 2100 | } |
| 2101 | void __add_digraph(_CharT __c1, _CharT __c2) |
| 2102 | { |
| 2103 | if (__icase_) |
| 2104 | __digraphs_.push_back(make_pair(__traits_.translate_nocase(__c1), |
| 2105 | __traits_.translate_nocase(__c2))); |
| 2106 | else if (__collate_) |
| 2107 | __digraphs_.push_back(make_pair(__traits_.translate(__c1), |
| 2108 | __traits_.translate(__c2))); |
| 2109 | else |
| 2110 | __digraphs_.push_back(make_pair(__c1, __c2)); |
| 2111 | } |
| 2112 | void __add_equivalence(const string_type& __s) |
| 2113 | {__equivalences_.push_back(__s);} |
| 2114 | void __add_class(ctype_base::mask __mask) |
| 2115 | {__mask_ |= __mask;} |
| 2116 | |
| 2117 | virtual string speak() const |
| 2118 | { |
| 2119 | ostringstream os; |
| 2120 | os << "__bracket_expression "; |
| 2121 | return os.str(); |
| 2122 | } |
| 2123 | }; |
| 2124 | |
| 2125 | template <class _CharT, class _Traits> |
| 2126 | void |
| 2127 | __bracket_expression<_CharT, _Traits>::__exec(__state& __s) const |
| 2128 | { |
| 2129 | bool __found = false; |
| 2130 | unsigned __consumed = 0; |
| 2131 | if (__s.__current_ != __s.__last_) |
| 2132 | { |
| 2133 | ++__consumed; |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2134 | if (__might_have_digraph_) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2135 | { |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2136 | const _CharT* __next = next(__s.__current_); |
| 2137 | if (__next != __s.__last_) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2138 | { |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2139 | pair<_CharT, _CharT> __ch2(*__s.__current_, *__next); |
| 2140 | if (__icase_) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2141 | { |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2142 | __ch2.first = __traits_.translate_nocase(__ch2.first); |
| 2143 | __ch2.second = __traits_.translate_nocase(__ch2.second); |
| 2144 | } |
| 2145 | else if (__collate_) |
| 2146 | { |
| 2147 | __ch2.first = __traits_.translate(__ch2.first); |
| 2148 | __ch2.second = __traits_.translate(__ch2.second); |
| 2149 | } |
| 2150 | if (!__traits_.lookup_collatename(&__ch2.first, &__ch2.first+2).empty()) |
| 2151 | { |
| 2152 | // __ch2 is a digraph in this locale |
| 2153 | ++__consumed; |
| 2154 | for (size_t __i = 0; __i < __digraphs_.size(); ++__i) |
| 2155 | { |
| 2156 | if (__ch2 == __digraphs_[__i]) |
| 2157 | { |
| 2158 | __found = true; |
| 2159 | goto __exit; |
| 2160 | } |
| 2161 | } |
| 2162 | if (__collate_ && !__ranges_.empty()) |
| 2163 | { |
| 2164 | string_type __s2 = __traits_.transform(&__ch2.first, |
| 2165 | &__ch2.first + 2); |
| 2166 | for (size_t __i = 0; __i < __ranges_.size(); ++__i) |
| 2167 | { |
| 2168 | if (__ranges_[__i].first <= __s2 && |
| 2169 | __s2 <= __ranges_[__i].second) |
| 2170 | { |
| 2171 | __found = true; |
| 2172 | goto __exit; |
| 2173 | } |
| 2174 | } |
| 2175 | } |
| 2176 | if (!__equivalences_.empty()) |
| 2177 | { |
| 2178 | string_type __s2 = __traits_.transform_primary(&__ch2.first, |
| 2179 | &__ch2.first + 2); |
| 2180 | for (size_t __i = 0; __i < __equivalences_.size(); ++__i) |
| 2181 | { |
| 2182 | if (__s2 == __equivalences_[__i]) |
| 2183 | { |
| 2184 | __found = true; |
| 2185 | goto __exit; |
| 2186 | } |
| 2187 | } |
| 2188 | } |
| 2189 | if (__traits_.isctype(__ch2.first, __mask_) && |
| 2190 | __traits_.isctype(__ch2.second, __mask_)) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2191 | { |
| 2192 | __found = true; |
| 2193 | goto __exit; |
| 2194 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2195 | goto __exit; |
| 2196 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2197 | } |
| 2198 | } |
| 2199 | // test *__s.__current_ as not a digraph |
| 2200 | _CharT __ch = *__s.__current_; |
| 2201 | if (__icase_) |
| 2202 | __ch = __traits_.translate_nocase(__ch); |
| 2203 | else if (__collate_) |
| 2204 | __ch = __traits_.translate(__ch); |
| 2205 | for (size_t __i = 0; __i < __chars_.size(); ++__i) |
| 2206 | { |
| 2207 | if (__ch == __chars_[__i]) |
| 2208 | { |
| 2209 | __found = true; |
| 2210 | goto __exit; |
| 2211 | } |
| 2212 | } |
| 2213 | if (!__ranges_.empty()) |
| 2214 | { |
| 2215 | string_type __s2 = __collate_ ? |
| 2216 | __traits_.transform(&__ch, &__ch + 1) : |
| 2217 | string_type(1, __ch); |
| 2218 | for (size_t __i = 0; __i < __ranges_.size(); ++__i) |
| 2219 | { |
| 2220 | if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second) |
| 2221 | { |
| 2222 | __found = true; |
| 2223 | goto __exit; |
| 2224 | } |
| 2225 | } |
| 2226 | } |
| 2227 | if (!__equivalences_.empty()) |
| 2228 | { |
| 2229 | string_type __s2 = __traits_.transform_primary(&__ch, &__ch + 1); |
| 2230 | for (size_t __i = 0; __i < __equivalences_.size(); ++__i) |
| 2231 | { |
| 2232 | if (__s2 == __equivalences_[__i]) |
| 2233 | { |
| 2234 | __found = true; |
| 2235 | goto __exit; |
| 2236 | } |
| 2237 | } |
| 2238 | } |
| 2239 | if (__traits_.isctype(__ch, __mask_)) |
| 2240 | __found = true; |
| 2241 | } |
| 2242 | else |
| 2243 | __found = __negate_; // force reject |
| 2244 | __exit: |
| 2245 | if (__found != __negate_) |
| 2246 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2247 | __s.__do_ = __state::__accept_and_consume; |
| 2248 | __s.__current_ += __consumed; |
| 2249 | __s.__node_ = this->first(); |
| 2250 | } |
| 2251 | else |
| 2252 | { |
| 2253 | __s.__do_ = __state::__reject; |
| 2254 | __s.__node_ = nullptr; |
| 2255 | } |
| 2256 | } |
| 2257 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2258 | template <class, class> class match_results; |
| 2259 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2260 | template <class _CharT, class _Traits = regex_traits<_CharT> > |
| 2261 | class basic_regex |
| 2262 | { |
| 2263 | public: |
| 2264 | // types: |
| 2265 | typedef _CharT value_type; |
| 2266 | typedef regex_constants::syntax_option_type flag_type; |
| 2267 | typedef typename _Traits::locale_type locale_type; |
| 2268 | |
| 2269 | private: |
| 2270 | _Traits __traits_; |
| 2271 | flag_type __flags_; |
| 2272 | unsigned __marked_count_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2273 | unsigned __loop_count_; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2274 | int __open_count_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2275 | shared_ptr<__empty_state<_CharT> > __start_; |
| 2276 | __owns_one_state<_CharT>* __end_; |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2277 | bool __left_anchor_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2278 | |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2279 | typedef _STD::__state<_CharT> __state; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2280 | typedef _STD::__node<_CharT> __node; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2281 | |
| 2282 | public: |
| 2283 | // constants: |
| 2284 | static const/*expr*/ regex_constants::syntax_option_type icase = regex_constants::icase; |
| 2285 | static const/*expr*/ regex_constants::syntax_option_type nosubs = regex_constants::nosubs; |
| 2286 | static const/*expr*/ regex_constants::syntax_option_type optimize = regex_constants::optimize; |
| 2287 | static const/*expr*/ regex_constants::syntax_option_type collate = regex_constants::collate; |
| 2288 | static const/*expr*/ regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript; |
| 2289 | static const/*expr*/ regex_constants::syntax_option_type basic = regex_constants::basic; |
| 2290 | static const/*expr*/ regex_constants::syntax_option_type extended = regex_constants::extended; |
| 2291 | static const/*expr*/ regex_constants::syntax_option_type awk = regex_constants::awk; |
| 2292 | static const/*expr*/ regex_constants::syntax_option_type grep = regex_constants::grep; |
| 2293 | static const/*expr*/ regex_constants::syntax_option_type egrep = regex_constants::egrep; |
| 2294 | |
| 2295 | // construct/copy/destroy: |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2296 | basic_regex() |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2297 | : __flags_(), __marked_count_(0), __loop_count_(0), __open_count_(0), |
| 2298 | __end_(0), __left_anchor_(false) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2299 | {} |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2300 | 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] | 2301 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
| 2302 | __end_(0), __left_anchor_(false) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2303 | {__parse(__p, __p + __traits_.length(__p));} |
| 2304 | basic_regex(const value_type* __p, size_t __len, flag_type __f) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2305 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
| 2306 | __end_(0), __left_anchor_(false) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2307 | {__parse(__p, __p + __len);} |
| 2308 | basic_regex(const basic_regex&); |
| 2309 | #ifdef _LIBCPP_MOVE |
| 2310 | basic_regex(basic_regex&&); |
| 2311 | #endif |
| 2312 | template <class _ST, class _SA> |
| 2313 | explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p, |
| 2314 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2315 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
| 2316 | __end_(0), __left_anchor_(false) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2317 | {__parse(__p.begin(), __p.end());} |
| 2318 | template <class _ForwardIterator> |
| 2319 | basic_regex(_ForwardIterator __first, _ForwardIterator __last, |
| 2320 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2321 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
| 2322 | __end_(0), __left_anchor_(false) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2323 | {__parse(__first, __last);} |
| 2324 | basic_regex(initializer_list<value_type> __il, |
| 2325 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2326 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
| 2327 | __end_(0), __left_anchor_(false) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2328 | {__parse(__il.begin(), __il.end());} |
| 2329 | |
| 2330 | ~basic_regex(); |
| 2331 | |
| 2332 | basic_regex& operator=(const basic_regex&); |
| 2333 | #ifdef _LIBCPP_MOVE |
| 2334 | basic_regex& operator=(basic_regex&&); |
| 2335 | #endif |
| 2336 | basic_regex& operator=(const value_type* __p); |
| 2337 | basic_regex& operator=(initializer_list<value_type> __il); |
| 2338 | template <class _ST, class _SA> |
| 2339 | basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p); |
| 2340 | |
| 2341 | // assign: |
| 2342 | basic_regex& assign(const basic_regex& __that); |
| 2343 | #ifdef _LIBCPP_MOVE |
| 2344 | basic_regex& assign(basic_regex&& __that); |
| 2345 | #endif |
| 2346 | basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript); |
| 2347 | basic_regex& assign(const value_type* __p, size_t __len, flag_type __f); |
| 2348 | template <class _ST, class _SA> |
| 2349 | basic_regex& assign(const basic_string<value_type, _ST, _SA>& __s, |
| 2350 | flag_type __f = regex_constants::ECMAScript); |
| 2351 | template <class _InputIterator> |
| 2352 | basic_regex& assign(_InputIterator __first, _InputIterator __last, |
| 2353 | flag_type __f = regex_constants::ECMAScript); |
| 2354 | basic_regex& assign(initializer_list<value_type> __il, |
| 2355 | flag_type = regex_constants::ECMAScript); |
| 2356 | |
| 2357 | // const operations: |
| 2358 | unsigned mark_count() const {return __marked_count_;} |
| 2359 | flag_type flags() const {return __flags_;} |
| 2360 | |
| 2361 | // locale: |
| 2362 | locale_type imbue(locale_type __loc) {return __traits_.imbue(__loc);} |
| 2363 | locale_type getloc() const {return __traits_.getloc();} |
| 2364 | |
| 2365 | // swap: |
| 2366 | void swap(basic_regex&); |
| 2367 | |
| 2368 | private: |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2369 | unsigned __loop_count() const {return __loop_count_;} |
| 2370 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2371 | template <class _ForwardIterator> |
| 2372 | void __parse(_ForwardIterator __first, _ForwardIterator __last); |
| 2373 | template <class _ForwardIterator> |
| 2374 | _ForwardIterator |
| 2375 | __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2376 | template <class _ForwardIterator> |
| 2377 | _ForwardIterator |
| 2378 | __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2379 | template <class _ForwardIterator> |
| 2380 | _ForwardIterator |
| 2381 | __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2382 | template <class _ForwardIterator> |
| 2383 | _ForwardIterator |
| 2384 | __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2385 | template <class _ForwardIterator> |
| 2386 | _ForwardIterator |
| 2387 | __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2388 | template <class _ForwardIterator> |
| 2389 | _ForwardIterator |
| 2390 | __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last); |
| 2391 | template <class _ForwardIterator> |
| 2392 | _ForwardIterator |
| 2393 | __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last); |
| 2394 | template <class _ForwardIterator> |
| 2395 | _ForwardIterator |
| 2396 | __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last); |
| 2397 | template <class _ForwardIterator> |
| 2398 | _ForwardIterator |
| 2399 | __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last); |
| 2400 | template <class _ForwardIterator> |
| 2401 | _ForwardIterator |
| 2402 | __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last); |
| 2403 | template <class _ForwardIterator> |
| 2404 | _ForwardIterator |
| 2405 | __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last); |
| 2406 | template <class _ForwardIterator> |
| 2407 | _ForwardIterator |
| 2408 | __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last); |
| 2409 | template <class _ForwardIterator> |
| 2410 | _ForwardIterator |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2411 | __parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last, |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2412 | __owns_one_state<_CharT>* __s, |
| 2413 | unsigned __mexp_begin, unsigned __mexp_end); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2414 | template <class _ForwardIterator> |
| 2415 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2416 | __parse_ERE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last); |
| 2417 | template <class _ForwardIterator> |
| 2418 | _ForwardIterator |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2419 | __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2420 | template <class _ForwardIterator> |
| 2421 | _ForwardIterator |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2422 | __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last, |
| 2423 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2424 | template <class _ForwardIterator> |
| 2425 | _ForwardIterator |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2426 | __parse_expression_term(_ForwardIterator __first, _ForwardIterator __last, |
| 2427 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2428 | template <class _ForwardIterator> |
| 2429 | _ForwardIterator |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2430 | __parse_equivalence_class(_ForwardIterator __first, _ForwardIterator __last, |
| 2431 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2432 | template <class _ForwardIterator> |
| 2433 | _ForwardIterator |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2434 | __parse_character_class(_ForwardIterator __first, _ForwardIterator __last, |
| 2435 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2436 | template <class _ForwardIterator> |
| 2437 | _ForwardIterator |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2438 | __parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last, |
| 2439 | basic_string<_CharT>& __col_sym); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2440 | template <class _ForwardIterator> |
| 2441 | _ForwardIterator |
| 2442 | __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2443 | template <class _ForwardIterator> |
| 2444 | _ForwardIterator |
| 2445 | __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2446 | template <class _ForwardIterator> |
| 2447 | _ForwardIterator |
| 2448 | __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last); |
| 2449 | template <class _ForwardIterator> |
| 2450 | _ForwardIterator |
| 2451 | __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2452 | template <class _ForwardIterator> |
| 2453 | _ForwardIterator |
| 2454 | __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last); |
| 2455 | template <class _ForwardIterator> |
| 2456 | _ForwardIterator |
| 2457 | __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last); |
| 2458 | template <class _ForwardIterator> |
| 2459 | _ForwardIterator |
| 2460 | __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2461 | |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2462 | void __push_l_anchor() {__left_anchor_ = true;} |
| 2463 | void __push_r_anchor(); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2464 | void __push_match_any(); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2465 | void __push_greedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s, |
| 2466 | unsigned __mexp_begin = 0, unsigned __mexp_end = 0) |
| 2467 | {__push_loop(__min, numeric_limits<size_t>::max(), __s, |
| 2468 | __mexp_begin, __mexp_end);} |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2469 | void __push_exact_repeat(int __count) {} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2470 | void __push_loop(size_t __min, size_t __max, __owns_one_state<_CharT>* __s, |
| 2471 | size_t __mexp_begin = 0, size_t __mexp_end = 0, |
| 2472 | bool __greedy = true); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2473 | __bracket_expression<_CharT, _Traits>* __start_matching_list(bool __negate); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2474 | void __push_char(value_type __c); |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 2475 | void __push_back_ref(int __i); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2476 | void __push_alternation() {} |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2477 | void __push_begin_marked_subexpression(); |
| 2478 | void __push_end_marked_subexpression(unsigned); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2479 | |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2480 | template <class _Allocator> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2481 | bool |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2482 | __search(const _CharT* __first, const _CharT* __last, |
| 2483 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2484 | regex_constants::match_flag_type __flags) const; |
| 2485 | |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2486 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2487 | bool |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2488 | __match_at_start(const _CharT* __first, const _CharT* __last, |
| 2489 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2490 | vector<size_t>& __lc, |
| 2491 | regex_constants::match_flag_type __flags) const; |
| 2492 | template <class _BidirectionalIterator, class _Allocator> |
| 2493 | bool |
| 2494 | __match_at_start_ecma(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 2495 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 2496 | regex_constants::match_flag_type __flags) const; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2497 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2498 | bool |
| 2499 | __match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last, |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2500 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2501 | vector<size_t>& __lc, |
| 2502 | regex_constants::match_flag_type __flags) const; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2503 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2504 | bool |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2505 | __match_at_start_posix_subs(const _CharT* __first, const _CharT* __last, |
| 2506 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2507 | vector<size_t>& __lc, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2508 | regex_constants::match_flag_type __flags) const; |
| 2509 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2510 | template <class _B, class _A, class _C, class _T> |
| 2511 | friend |
| 2512 | bool |
| 2513 | regex_search(_B, _B, match_results<_B, _A>&, const basic_regex<_C, _T>&, |
| 2514 | regex_constants::match_flag_type); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2515 | |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2516 | template <class _A, class _C, class _T> |
| 2517 | friend |
| 2518 | bool |
| 2519 | regex_search(const _C*, const _C*, match_results<const _C*, _A>&, |
| 2520 | const basic_regex<_C, _T>&, regex_constants::match_flag_type); |
| 2521 | |
| 2522 | template <class _B, class _C, class _T> |
| 2523 | friend |
| 2524 | bool |
| 2525 | regex_search(_B, _B, const basic_regex<_C, _T>&, |
| 2526 | regex_constants::match_flag_type); |
| 2527 | |
| 2528 | template <class _C, class _T> |
| 2529 | friend |
| 2530 | bool |
| 2531 | regex_search(const _C*, const _C*, |
| 2532 | const basic_regex<_C, _T>&, regex_constants::match_flag_type); |
| 2533 | |
| 2534 | template <class _C, class _A, class _T> |
| 2535 | friend |
| 2536 | bool |
| 2537 | regex_search(const _C*, match_results<const _C*, _A>&, const basic_regex<_C, _T>&, |
| 2538 | regex_constants::match_flag_type); |
| 2539 | |
| 2540 | template <class _ST, class _SA, class _C, class _T> |
| 2541 | friend |
| 2542 | bool |
| 2543 | regex_search(const basic_string<_C, _ST, _SA>& __s, |
| 2544 | const basic_regex<_C, _T>& __e, |
| 2545 | regex_constants::match_flag_type __flags); |
| 2546 | |
| 2547 | template <class _ST, class _SA, class _A, class _C, class _T> |
| 2548 | friend |
| 2549 | bool |
| 2550 | regex_search(const basic_string<_C, _ST, _SA>& __s, |
| 2551 | match_results<typename basic_string<_C, _ST, _SA>::const_iterator, _A>&, |
| 2552 | const basic_regex<_C, _T>& __e, |
| 2553 | regex_constants::match_flag_type __flags); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2554 | }; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2555 | |
| 2556 | template <class _CharT, class _Traits> |
| 2557 | basic_regex<_CharT, _Traits>::~basic_regex() |
| 2558 | { |
| 2559 | } |
| 2560 | |
| 2561 | template <class _CharT, class _Traits> |
| 2562 | template <class _ForwardIterator> |
| 2563 | void |
| 2564 | basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first, |
| 2565 | _ForwardIterator __last) |
| 2566 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2567 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2568 | unique_ptr<__node> __h(new __end_state<_CharT>); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2569 | __start_.reset(new __empty_state<_CharT>(__h.get())); |
| 2570 | __h.release(); |
| 2571 | __end_ = __start_.get(); |
| 2572 | } |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2573 | switch (__flags_ & 0x3F0) |
| 2574 | { |
| 2575 | case ECMAScript: |
| 2576 | break; |
| 2577 | case basic: |
| 2578 | __parse_basic_reg_exp(__first, __last); |
| 2579 | break; |
| 2580 | case extended: |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2581 | __parse_extended_reg_exp(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2582 | break; |
| 2583 | case awk: |
| 2584 | break; |
| 2585 | case grep: |
| 2586 | break; |
| 2587 | case egrep: |
| 2588 | break; |
| 2589 | default: |
| 2590 | throw regex_error(regex_constants::error_temp); |
| 2591 | } |
| 2592 | } |
| 2593 | |
| 2594 | template <class _CharT, class _Traits> |
| 2595 | template <class _ForwardIterator> |
| 2596 | _ForwardIterator |
| 2597 | basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first, |
| 2598 | _ForwardIterator __last) |
| 2599 | { |
| 2600 | if (__first != __last) |
| 2601 | { |
| 2602 | if (*__first == '^') |
| 2603 | { |
| 2604 | __push_l_anchor(); |
| 2605 | ++__first; |
| 2606 | } |
| 2607 | if (__first != __last) |
| 2608 | { |
| 2609 | __first = __parse_RE_expression(__first, __last); |
| 2610 | if (__first != __last) |
| 2611 | { |
| 2612 | _ForwardIterator __temp = next(__first); |
| 2613 | if (__temp == __last && *__first == '$') |
| 2614 | { |
| 2615 | __push_r_anchor(); |
| 2616 | ++__first; |
| 2617 | } |
| 2618 | } |
| 2619 | } |
| 2620 | if (__first != __last) |
| 2621 | throw regex_error(regex_constants::error_temp); |
| 2622 | } |
| 2623 | return __first; |
| 2624 | } |
| 2625 | |
| 2626 | template <class _CharT, class _Traits> |
| 2627 | template <class _ForwardIterator> |
| 2628 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2629 | basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first, |
| 2630 | _ForwardIterator __last) |
| 2631 | { |
| 2632 | while (true) |
| 2633 | { |
| 2634 | _ForwardIterator __temp = __parse_ERE_branch(__first, __last); |
| 2635 | if (__temp == __first) |
| 2636 | throw regex_error(regex_constants::error_temp); |
| 2637 | __first = __temp; |
| 2638 | if (__first == __last) |
| 2639 | break; |
| 2640 | if (*__first != '|') |
| 2641 | throw regex_error(regex_constants::error_temp); |
| 2642 | __push_alternation(); |
| 2643 | ++__first; |
| 2644 | } |
| 2645 | return __first; |
| 2646 | } |
| 2647 | |
| 2648 | template <class _CharT, class _Traits> |
| 2649 | template <class _ForwardIterator> |
| 2650 | _ForwardIterator |
| 2651 | basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first, |
| 2652 | _ForwardIterator __last) |
| 2653 | { |
| 2654 | _ForwardIterator __temp = __parse_ERE_expression(__first, __last); |
| 2655 | if (__temp == __first) |
| 2656 | throw regex_error(regex_constants::error_temp); |
| 2657 | do |
| 2658 | { |
| 2659 | __first = __temp; |
| 2660 | __temp = __parse_ERE_expression(__first, __last); |
| 2661 | } while (__temp != __first); |
| 2662 | return __first; |
| 2663 | } |
| 2664 | |
| 2665 | template <class _CharT, class _Traits> |
| 2666 | template <class _ForwardIterator> |
| 2667 | _ForwardIterator |
| 2668 | basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first, |
| 2669 | _ForwardIterator __last) |
| 2670 | { |
| 2671 | _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last); |
| 2672 | if (__temp == __first && __temp != __last) |
| 2673 | { |
| 2674 | switch (*__temp) |
| 2675 | { |
| 2676 | case '^': |
| 2677 | __push_l_anchor(); |
| 2678 | ++__temp; |
| 2679 | break; |
| 2680 | case '$': |
| 2681 | __push_r_anchor(); |
| 2682 | ++__temp; |
| 2683 | break; |
| 2684 | case '(': |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2685 | __push_begin_marked_subexpression(); |
| 2686 | unsigned __temp_count = __marked_count_; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2687 | ++__open_count_; |
| 2688 | __temp = __parse_extended_reg_exp(++__temp, __last); |
| 2689 | if (__temp == __last || *__temp != ')') |
| 2690 | throw regex_error(regex_constants::error_paren); |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2691 | __push_end_marked_subexpression(__temp_count); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2692 | --__open_count_; |
| 2693 | ++__temp; |
| 2694 | break; |
| 2695 | } |
| 2696 | } |
| 2697 | if (__temp != __first) |
| 2698 | __temp = __parse_ERE_dupl_symbol(__temp, __last); |
| 2699 | __first = __temp; |
| 2700 | return __first; |
| 2701 | } |
| 2702 | |
| 2703 | template <class _CharT, class _Traits> |
| 2704 | template <class _ForwardIterator> |
| 2705 | _ForwardIterator |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2706 | basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first, |
| 2707 | _ForwardIterator __last) |
| 2708 | { |
| 2709 | while (true) |
| 2710 | { |
| 2711 | _ForwardIterator __temp = __parse_simple_RE(__first, __last); |
| 2712 | if (__temp == __first) |
| 2713 | break; |
| 2714 | __first = __temp; |
| 2715 | } |
| 2716 | return __first; |
| 2717 | } |
| 2718 | |
| 2719 | template <class _CharT, class _Traits> |
| 2720 | template <class _ForwardIterator> |
| 2721 | _ForwardIterator |
| 2722 | basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first, |
| 2723 | _ForwardIterator __last) |
| 2724 | { |
| 2725 | if (__first != __last) |
| 2726 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2727 | __owns_one_state<_CharT>* __e = __end_; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2728 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2729 | _ForwardIterator __temp = __parse_nondupl_RE(__first, __last); |
| 2730 | if (__temp != __first) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2731 | __first = __parse_RE_dupl_symbol(__temp, __last, __e, |
| 2732 | __mexp_begin+1, __marked_count_+1); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2733 | } |
| 2734 | return __first; |
| 2735 | } |
| 2736 | |
| 2737 | template <class _CharT, class _Traits> |
| 2738 | template <class _ForwardIterator> |
| 2739 | _ForwardIterator |
| 2740 | basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first, |
| 2741 | _ForwardIterator __last) |
| 2742 | { |
| 2743 | _ForwardIterator __temp = __first; |
| 2744 | __first = __parse_one_char_or_coll_elem_RE(__first, __last); |
| 2745 | if (__temp == __first) |
| 2746 | { |
| 2747 | __temp = __parse_Back_open_paren(__first, __last); |
| 2748 | if (__temp != __first) |
| 2749 | { |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2750 | __push_begin_marked_subexpression(); |
| 2751 | unsigned __temp_count = __marked_count_; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2752 | __first = __parse_RE_expression(__temp, __last); |
| 2753 | __temp = __parse_Back_close_paren(__first, __last); |
| 2754 | if (__temp == __first) |
| 2755 | throw regex_error(regex_constants::error_paren); |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2756 | __push_end_marked_subexpression(__temp_count); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2757 | __first = __temp; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2758 | } |
| 2759 | else |
| 2760 | __first = __parse_BACKREF(__first, __last); |
| 2761 | } |
| 2762 | return __first; |
| 2763 | } |
| 2764 | |
| 2765 | template <class _CharT, class _Traits> |
| 2766 | template <class _ForwardIterator> |
| 2767 | _ForwardIterator |
| 2768 | basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE( |
| 2769 | _ForwardIterator __first, |
| 2770 | _ForwardIterator __last) |
| 2771 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2772 | _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2773 | if (__temp == __first) |
| 2774 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2775 | __temp = __parse_QUOTED_CHAR(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2776 | if (__temp == __first) |
| 2777 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2778 | if (__temp != __last && *__temp == '.') |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2779 | { |
| 2780 | __push_match_any(); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2781 | ++__temp; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2782 | } |
| 2783 | else |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2784 | __temp = __parse_bracket_expression(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2785 | } |
| 2786 | } |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2787 | __first = __temp; |
| 2788 | return __first; |
| 2789 | } |
| 2790 | |
| 2791 | template <class _CharT, class _Traits> |
| 2792 | template <class _ForwardIterator> |
| 2793 | _ForwardIterator |
| 2794 | basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE( |
| 2795 | _ForwardIterator __first, |
| 2796 | _ForwardIterator __last) |
| 2797 | { |
| 2798 | _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last); |
| 2799 | if (__temp == __first) |
| 2800 | { |
| 2801 | __temp = __parse_QUOTED_CHAR_ERE(__first, __last); |
| 2802 | if (__temp == __first) |
| 2803 | { |
| 2804 | if (__temp != __last && *__temp == '.') |
| 2805 | { |
| 2806 | __push_match_any(); |
| 2807 | ++__temp; |
| 2808 | } |
| 2809 | else |
| 2810 | __temp = __parse_bracket_expression(__first, __last); |
| 2811 | } |
| 2812 | } |
| 2813 | __first = __temp; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2814 | return __first; |
| 2815 | } |
| 2816 | |
| 2817 | template <class _CharT, class _Traits> |
| 2818 | template <class _ForwardIterator> |
| 2819 | _ForwardIterator |
| 2820 | basic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first, |
| 2821 | _ForwardIterator __last) |
| 2822 | { |
| 2823 | if (__first != __last) |
| 2824 | { |
| 2825 | _ForwardIterator __temp = next(__first); |
| 2826 | if (__temp != __last) |
| 2827 | { |
| 2828 | if (*__first == '\\' && *__temp == '(') |
| 2829 | __first = ++__temp; |
| 2830 | } |
| 2831 | } |
| 2832 | return __first; |
| 2833 | } |
| 2834 | |
| 2835 | template <class _CharT, class _Traits> |
| 2836 | template <class _ForwardIterator> |
| 2837 | _ForwardIterator |
| 2838 | basic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first, |
| 2839 | _ForwardIterator __last) |
| 2840 | { |
| 2841 | if (__first != __last) |
| 2842 | { |
| 2843 | _ForwardIterator __temp = next(__first); |
| 2844 | if (__temp != __last) |
| 2845 | { |
| 2846 | if (*__first == '\\' && *__temp == ')') |
| 2847 | __first = ++__temp; |
| 2848 | } |
| 2849 | } |
| 2850 | return __first; |
| 2851 | } |
| 2852 | |
| 2853 | template <class _CharT, class _Traits> |
| 2854 | template <class _ForwardIterator> |
| 2855 | _ForwardIterator |
| 2856 | basic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first, |
| 2857 | _ForwardIterator __last) |
| 2858 | { |
| 2859 | if (__first != __last) |
| 2860 | { |
| 2861 | _ForwardIterator __temp = next(__first); |
| 2862 | if (__temp != __last) |
| 2863 | { |
| 2864 | if (*__first == '\\' && *__temp == '{') |
| 2865 | __first = ++__temp; |
| 2866 | } |
| 2867 | } |
| 2868 | return __first; |
| 2869 | } |
| 2870 | |
| 2871 | template <class _CharT, class _Traits> |
| 2872 | template <class _ForwardIterator> |
| 2873 | _ForwardIterator |
| 2874 | basic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first, |
| 2875 | _ForwardIterator __last) |
| 2876 | { |
| 2877 | if (__first != __last) |
| 2878 | { |
| 2879 | _ForwardIterator __temp = next(__first); |
| 2880 | if (__temp != __last) |
| 2881 | { |
| 2882 | if (*__first == '\\' && *__temp == '}') |
| 2883 | __first = ++__temp; |
| 2884 | } |
| 2885 | } |
| 2886 | return __first; |
| 2887 | } |
| 2888 | |
| 2889 | template <class _CharT, class _Traits> |
| 2890 | template <class _ForwardIterator> |
| 2891 | _ForwardIterator |
| 2892 | basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first, |
| 2893 | _ForwardIterator __last) |
| 2894 | { |
| 2895 | if (__first != __last) |
| 2896 | { |
| 2897 | _ForwardIterator __temp = next(__first); |
| 2898 | if (__temp != __last) |
| 2899 | { |
| 2900 | if (*__first == '\\' && '1' <= *__temp && *__temp <= '9') |
| 2901 | { |
| 2902 | __push_back_ref(*__temp - '0'); |
| 2903 | __first = ++__temp; |
| 2904 | } |
| 2905 | } |
| 2906 | } |
| 2907 | return __first; |
| 2908 | } |
| 2909 | |
| 2910 | template <class _CharT, class _Traits> |
| 2911 | template <class _ForwardIterator> |
| 2912 | _ForwardIterator |
| 2913 | basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first, |
| 2914 | _ForwardIterator __last) |
| 2915 | { |
| 2916 | if (__first != __last) |
| 2917 | { |
| 2918 | _ForwardIterator __temp = next(__first); |
| 2919 | if (__temp == __last && *__first == '$') |
| 2920 | return __first; |
| 2921 | // Not called inside a bracket |
| 2922 | if (*__first == '.' || *__first == '\\' || *__first == '[') |
| 2923 | return __first; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2924 | __push_char(*__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2925 | ++__first; |
| 2926 | } |
| 2927 | return __first; |
| 2928 | } |
| 2929 | |
| 2930 | template <class _CharT, class _Traits> |
| 2931 | template <class _ForwardIterator> |
| 2932 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2933 | basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first, |
| 2934 | _ForwardIterator __last) |
| 2935 | { |
| 2936 | if (__first != __last) |
| 2937 | { |
| 2938 | switch (*__first) |
| 2939 | { |
| 2940 | case '^': |
| 2941 | case '.': |
| 2942 | case '[': |
| 2943 | case '$': |
| 2944 | case '(': |
| 2945 | case '|': |
| 2946 | case '*': |
| 2947 | case '+': |
| 2948 | case '?': |
| 2949 | case '{': |
| 2950 | case '\\': |
| 2951 | break; |
| 2952 | case ')': |
| 2953 | if (__open_count_ == 0) |
| 2954 | { |
| 2955 | __push_char(*__first); |
| 2956 | ++__first; |
| 2957 | } |
| 2958 | break; |
| 2959 | default: |
| 2960 | __push_char(*__first); |
| 2961 | ++__first; |
| 2962 | break; |
| 2963 | } |
| 2964 | } |
| 2965 | return __first; |
| 2966 | } |
| 2967 | |
| 2968 | template <class _CharT, class _Traits> |
| 2969 | template <class _ForwardIterator> |
| 2970 | _ForwardIterator |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2971 | basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first, |
| 2972 | _ForwardIterator __last) |
| 2973 | { |
| 2974 | if (__first != __last) |
| 2975 | { |
| 2976 | _ForwardIterator __temp = next(__first); |
| 2977 | if (__temp != __last) |
| 2978 | { |
| 2979 | if (*__first == '\\') |
| 2980 | { |
| 2981 | switch (*__temp) |
| 2982 | { |
| 2983 | case '^': |
| 2984 | case '.': |
| 2985 | case '*': |
| 2986 | case '[': |
| 2987 | case '$': |
| 2988 | case '\\': |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2989 | __push_char(*__temp); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2990 | __first = ++__temp; |
| 2991 | break; |
| 2992 | } |
| 2993 | } |
| 2994 | } |
| 2995 | } |
| 2996 | return __first; |
| 2997 | } |
| 2998 | |
| 2999 | template <class _CharT, class _Traits> |
| 3000 | template <class _ForwardIterator> |
| 3001 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3002 | basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first, |
| 3003 | _ForwardIterator __last) |
| 3004 | { |
| 3005 | if (__first != __last) |
| 3006 | { |
| 3007 | _ForwardIterator __temp = next(__first); |
| 3008 | if (__temp != __last) |
| 3009 | { |
| 3010 | if (*__first == '\\') |
| 3011 | { |
| 3012 | switch (*__temp) |
| 3013 | { |
| 3014 | case '^': |
| 3015 | case '.': |
| 3016 | case '*': |
| 3017 | case '[': |
| 3018 | case '$': |
| 3019 | case '\\': |
| 3020 | case '(': |
| 3021 | case ')': |
| 3022 | case '|': |
| 3023 | case '+': |
| 3024 | case '?': |
| 3025 | case '{': |
| 3026 | __push_char(*__temp); |
| 3027 | __first = ++__temp; |
| 3028 | break; |
| 3029 | } |
| 3030 | } |
| 3031 | } |
| 3032 | } |
| 3033 | return __first; |
| 3034 | } |
| 3035 | |
| 3036 | template <class _CharT, class _Traits> |
| 3037 | template <class _ForwardIterator> |
| 3038 | _ForwardIterator |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3039 | basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3040 | _ForwardIterator __last, |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3041 | __owns_one_state<_CharT>* __s, |
| 3042 | unsigned __mexp_begin, |
| 3043 | unsigned __mexp_end) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3044 | { |
| 3045 | if (__first != __last) |
| 3046 | { |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3047 | if (*__first == '*') |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3048 | { |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3049 | __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3050 | ++__first; |
| 3051 | } |
| 3052 | else |
| 3053 | { |
| 3054 | _ForwardIterator __temp = __parse_Back_open_brace(__first, __last); |
| 3055 | if (__temp != __first) |
| 3056 | { |
| 3057 | int __min = 0; |
| 3058 | __first = __temp; |
| 3059 | __temp = __parse_DUP_COUNT(__first, __last, __min); |
| 3060 | if (__temp == __first) |
| 3061 | throw regex_error(regex_constants::error_badbrace); |
| 3062 | __first = __temp; |
| 3063 | if (__first == __last) |
| 3064 | throw regex_error(regex_constants::error_brace); |
| 3065 | if (*__first != ',') |
| 3066 | { |
| 3067 | __temp = __parse_Back_close_brace(__first, __last); |
| 3068 | if (__temp == __first) |
| 3069 | throw regex_error(regex_constants::error_brace); |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 3070 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, |
| 3071 | true); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3072 | __first = __temp; |
| 3073 | } |
| 3074 | else |
| 3075 | { |
| 3076 | ++__first; // consume ',' |
| 3077 | int __max = -1; |
| 3078 | __first = __parse_DUP_COUNT(__first, __last, __max); |
| 3079 | __temp = __parse_Back_close_brace(__first, __last); |
| 3080 | if (__temp == __first) |
| 3081 | throw regex_error(regex_constants::error_brace); |
| 3082 | if (__max == -1) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3083 | __push_greedy_inf_repeat(__min, __s, __mexp_end, __mexp_end); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3084 | else |
| 3085 | { |
| 3086 | if (__max < __min) |
| 3087 | throw regex_error(regex_constants::error_badbrace); |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 3088 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, |
| 3089 | true); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3090 | } |
| 3091 | __first = __temp; |
| 3092 | } |
| 3093 | } |
| 3094 | } |
| 3095 | } |
| 3096 | return __first; |
| 3097 | } |
| 3098 | |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3099 | template <class _CharT, class _Traits> |
| 3100 | template <class _ForwardIterator> |
| 3101 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3102 | basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first, |
| 3103 | _ForwardIterator __last) |
| 3104 | { |
| 3105 | if (__first != __last) |
| 3106 | { |
| 3107 | switch (*__first) |
| 3108 | { |
| 3109 | case '*': |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3110 | __push_greedy_inf_repeat(0, nullptr); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3111 | ++__first; |
| 3112 | break; |
| 3113 | case '+': |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3114 | __push_greedy_inf_repeat(1, nullptr); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3115 | ++__first; |
| 3116 | break; |
| 3117 | case '?': |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3118 | __push_loop(0, 1, nullptr); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3119 | ++__first; |
| 3120 | break; |
| 3121 | case '{': |
| 3122 | { |
| 3123 | int __min; |
| 3124 | _ForwardIterator __temp = __parse_DUP_COUNT(__first, __last, __min); |
| 3125 | if (__temp == __first) |
| 3126 | throw regex_error(regex_constants::error_badbrace); |
| 3127 | __first = __temp; |
| 3128 | if (__first == __last) |
| 3129 | throw regex_error(regex_constants::error_brace); |
| 3130 | switch (*__first) |
| 3131 | { |
| 3132 | case '}': |
| 3133 | __push_exact_repeat(__min); |
| 3134 | ++__first; |
| 3135 | break; |
| 3136 | case ',': |
| 3137 | if (++__first == __last) |
| 3138 | throw regex_error(regex_constants::error_badbrace); |
| 3139 | if (*__first == '}') |
| 3140 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3141 | __push_greedy_inf_repeat(__min, nullptr); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3142 | ++__first; |
| 3143 | } |
| 3144 | else |
| 3145 | { |
| 3146 | int __max; |
| 3147 | __temp = __parse_DUP_COUNT(__first, __last, __max); |
| 3148 | if (__temp == __first) |
| 3149 | throw regex_error(regex_constants::error_brace); |
| 3150 | __first = __temp; |
| 3151 | if (__first == __last || *__first != '}') |
| 3152 | throw regex_error(regex_constants::error_brace); |
| 3153 | ++__first; |
| 3154 | if (__max < __min) |
| 3155 | throw regex_error(regex_constants::error_badbrace); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3156 | __push_loop(__min, __max, nullptr); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3157 | } |
| 3158 | default: |
| 3159 | throw regex_error(regex_constants::error_badbrace); |
| 3160 | } |
| 3161 | } |
| 3162 | break; |
| 3163 | } |
| 3164 | } |
| 3165 | return __first; |
| 3166 | } |
| 3167 | |
| 3168 | template <class _CharT, class _Traits> |
| 3169 | template <class _ForwardIterator> |
| 3170 | _ForwardIterator |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3171 | basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first, |
| 3172 | _ForwardIterator __last) |
| 3173 | { |
| 3174 | if (__first != __last && *__first == '[') |
| 3175 | { |
| 3176 | if (++__first == __last) |
| 3177 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3178 | bool __negate = false; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3179 | if (*__first == '^') |
| 3180 | { |
| 3181 | ++__first; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3182 | __negate = true; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3183 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3184 | __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate); |
| 3185 | // __ml owned by *this |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3186 | if (__first == __last) |
| 3187 | throw regex_error(regex_constants::error_brack); |
| 3188 | if (*__first == ']') |
| 3189 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3190 | __ml->__add_char(']'); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3191 | ++__first; |
| 3192 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3193 | __first = __parse_follow_list(__first, __last, __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3194 | if (__first == __last) |
| 3195 | throw regex_error(regex_constants::error_brack); |
| 3196 | if (*__first == '-') |
| 3197 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3198 | __ml->__add_char('-'); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3199 | ++__first; |
| 3200 | } |
| 3201 | if (__first == __last || *__first != ']') |
| 3202 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3203 | ++__first; |
| 3204 | } |
| 3205 | return __first; |
| 3206 | } |
| 3207 | |
| 3208 | template <class _CharT, class _Traits> |
| 3209 | template <class _ForwardIterator> |
| 3210 | _ForwardIterator |
| 3211 | basic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3212 | _ForwardIterator __last, |
| 3213 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3214 | { |
| 3215 | if (__first != __last) |
| 3216 | { |
| 3217 | while (true) |
| 3218 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3219 | _ForwardIterator __temp = __parse_expression_term(__first, __last, |
| 3220 | __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3221 | if (__temp == __first) |
| 3222 | break; |
| 3223 | __first = __temp; |
| 3224 | } |
| 3225 | } |
| 3226 | return __first; |
| 3227 | } |
| 3228 | |
| 3229 | template <class _CharT, class _Traits> |
| 3230 | template <class _ForwardIterator> |
| 3231 | _ForwardIterator |
| 3232 | basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3233 | _ForwardIterator __last, |
| 3234 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3235 | { |
| 3236 | if (__first != __last && *__first != ']') |
| 3237 | { |
| 3238 | bool __parsed_one = false; |
| 3239 | _ForwardIterator __temp = next(__first); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3240 | basic_string<_CharT> __start_range; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3241 | if (__temp != __last && *__first == '[') |
| 3242 | { |
| 3243 | if (*__temp == '=') |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3244 | return __parse_equivalence_class(++__temp, __last, __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3245 | else if (*__temp == ':') |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3246 | return __parse_character_class(++__temp, __last, __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3247 | else if (*__temp == '.') |
| 3248 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3249 | __first = __parse_collating_symbol(++__temp, __last, __start_range); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3250 | __parsed_one = true; |
| 3251 | } |
| 3252 | } |
| 3253 | if (!__parsed_one) |
| 3254 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3255 | __start_range = *__first; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3256 | ++__first; |
| 3257 | } |
| 3258 | if (__first != __last && *__first != ']') |
| 3259 | { |
| 3260 | __temp = next(__first); |
| 3261 | if (__temp != __last && *__first == '-' && *__temp != ']') |
| 3262 | { |
| 3263 | // parse a range |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3264 | basic_string<_CharT> __end_range; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3265 | __first = __temp; |
| 3266 | ++__temp; |
| 3267 | if (__temp != __last && *__first == '[' && *__temp == '.') |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3268 | __first = __parse_collating_symbol(++__temp, __last, __end_range); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3269 | else |
| 3270 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3271 | __end_range = *__first; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3272 | ++__first; |
| 3273 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3274 | __ml->__add_range(_STD::move(__start_range), _STD::move(__end_range)); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3275 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3276 | else |
| 3277 | { |
| 3278 | if (__start_range.size() == 1) |
| 3279 | __ml->__add_char(__start_range[0]); |
| 3280 | else |
| 3281 | __ml->__add_digraph(__start_range[0], __start_range[1]); |
| 3282 | } |
| 3283 | } |
| 3284 | else |
| 3285 | { |
| 3286 | if (__start_range.size() == 1) |
| 3287 | __ml->__add_char(__start_range[0]); |
| 3288 | else |
| 3289 | __ml->__add_digraph(__start_range[0], __start_range[1]); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3290 | } |
| 3291 | } |
| 3292 | return __first; |
| 3293 | } |
| 3294 | |
| 3295 | template <class _CharT, class _Traits> |
| 3296 | template <class _ForwardIterator> |
| 3297 | _ForwardIterator |
| 3298 | basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3299 | _ForwardIterator __last, |
| 3300 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3301 | { |
| 3302 | // Found [= |
| 3303 | // This means =] must exist |
| 3304 | value_type _Equal_close[2] = {'=', ']'}; |
| 3305 | _ForwardIterator __temp = _STD::search(__first, __last, _Equal_close, |
| 3306 | _Equal_close+2); |
| 3307 | if (__temp == __last) |
| 3308 | throw regex_error(regex_constants::error_brack); |
| 3309 | // [__first, __temp) contains all text in [= ... =] |
| 3310 | typedef typename _Traits::string_type string_type; |
| 3311 | string_type __collate_name = |
| 3312 | __traits_.lookup_collatename(__first, __temp); |
| 3313 | if (__collate_name.empty()) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3314 | throw regex_error(regex_constants::error_collate); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3315 | string_type __equiv_name = |
| 3316 | __traits_.transform_primary(__collate_name.begin(), |
| 3317 | __collate_name.end()); |
| 3318 | if (!__equiv_name.empty()) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3319 | __ml->__add_equivalence(__equiv_name); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3320 | else |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3321 | { |
| 3322 | switch (__collate_name.size()) |
| 3323 | { |
| 3324 | case 1: |
| 3325 | __ml->__add_char(__collate_name[0]); |
| 3326 | break; |
| 3327 | case 2: |
| 3328 | __ml->__add_digraph(__collate_name[0], __collate_name[1]); |
| 3329 | break; |
| 3330 | default: |
| 3331 | throw regex_error(regex_constants::error_collate); |
| 3332 | } |
| 3333 | } |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3334 | __first = next(__temp, 2); |
| 3335 | return __first; |
| 3336 | } |
| 3337 | |
| 3338 | template <class _CharT, class _Traits> |
| 3339 | template <class _ForwardIterator> |
| 3340 | _ForwardIterator |
| 3341 | basic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3342 | _ForwardIterator __last, |
| 3343 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3344 | { |
| 3345 | // Found [: |
| 3346 | // This means :] must exist |
| 3347 | value_type _Colon_close[2] = {':', ']'}; |
| 3348 | _ForwardIterator __temp = _STD::search(__first, __last, _Colon_close, |
| 3349 | _Colon_close+2); |
| 3350 | if (__temp == __last) |
| 3351 | throw regex_error(regex_constants::error_brack); |
| 3352 | // [__first, __temp) contains all text in [: ... :] |
| 3353 | typedef typename _Traits::char_class_type char_class_type; |
| 3354 | char_class_type __class_type = |
| 3355 | __traits_.lookup_classname(__first, __temp, __flags_ & icase); |
| 3356 | if (__class_type == 0) |
| 3357 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3358 | __ml->__add_class(__class_type); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3359 | __first = next(__temp, 2); |
| 3360 | return __first; |
| 3361 | } |
| 3362 | |
| 3363 | template <class _CharT, class _Traits> |
| 3364 | template <class _ForwardIterator> |
| 3365 | _ForwardIterator |
| 3366 | basic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3367 | _ForwardIterator __last, |
| 3368 | basic_string<_CharT>& __col_sym) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3369 | { |
| 3370 | // Found [. |
| 3371 | // This means .] must exist |
| 3372 | value_type _Dot_close[2] = {'.', ']'}; |
| 3373 | _ForwardIterator __temp = _STD::search(__first, __last, _Dot_close, |
| 3374 | _Dot_close+2); |
| 3375 | if (__temp == __last) |
| 3376 | throw regex_error(regex_constants::error_brack); |
| 3377 | // [__first, __temp) contains all text in [. ... .] |
| 3378 | typedef typename _Traits::string_type string_type; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3379 | __col_sym = __traits_.lookup_collatename(__first, __temp); |
| 3380 | switch (__col_sym.size()) |
| 3381 | { |
| 3382 | case 1: |
| 3383 | case 2: |
| 3384 | break; |
| 3385 | default: |
| 3386 | throw regex_error(regex_constants::error_collate); |
| 3387 | } |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3388 | __first = next(__temp, 2); |
| 3389 | return __first; |
| 3390 | } |
| 3391 | |
| 3392 | template <class _CharT, class _Traits> |
| 3393 | template <class _ForwardIterator> |
| 3394 | _ForwardIterator |
| 3395 | basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first, |
| 3396 | _ForwardIterator __last, |
| 3397 | int& __c) |
| 3398 | { |
| 3399 | if (__first != __last && '0' <= *__first && *__first <= '9') |
| 3400 | { |
| 3401 | __c = *__first - '0'; |
| 3402 | for (++__first; __first != __last && '0' <= *__first && *__first <= '9'; |
| 3403 | ++__first) |
| 3404 | { |
| 3405 | __c *= 10; |
| 3406 | __c += *__first - '0'; |
| 3407 | } |
| 3408 | } |
| 3409 | return __first; |
| 3410 | } |
| 3411 | |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3412 | template <class _CharT, class _Traits> |
| 3413 | void |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3414 | basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max, |
| 3415 | __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end, |
| 3416 | bool __greedy) |
| 3417 | { |
| 3418 | unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first())); |
| 3419 | __end_->first() = nullptr; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 3420 | unique_ptr<__loop<_CharT> > __e2(new __loop<_CharT>(__loop_count_, |
| 3421 | __s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy, |
| 3422 | __min, __max)); |
| 3423 | __s->first() = nullptr; |
| 3424 | __e1.release(); |
| 3425 | __end_->first() = new __repeat_one_loop<_CharT>(__e2.get()); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3426 | __end_ = __e2->second(); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 3427 | __s->first() = __e2.release(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3428 | ++__loop_count_; |
| 3429 | } |
| 3430 | |
| 3431 | template <class _CharT, class _Traits> |
| 3432 | void |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3433 | basic_regex<_CharT, _Traits>::__push_char(value_type __c) |
| 3434 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3435 | if (flags() & icase) |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 3436 | __end_->first() = new __match_char_icase<_CharT, _Traits> |
| 3437 | (__traits_, __c, __end_->first()); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3438 | else if (flags() & collate) |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 3439 | __end_->first() = new __match_char_collate<_CharT, _Traits> |
| 3440 | (__traits_, __c, __end_->first()); |
| 3441 | else |
| 3442 | __end_->first() = new __match_char<_CharT>(__c, __end_->first()); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3443 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3444 | } |
| 3445 | |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3446 | template <class _CharT, class _Traits> |
| 3447 | void |
| 3448 | basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression() |
| 3449 | { |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 3450 | if (!(__flags_ & nosubs)) |
| 3451 | { |
| 3452 | __end_->first() = |
| 3453 | new __begin_marked_subexpression<_CharT>(++__marked_count_, |
| 3454 | __end_->first()); |
| 3455 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 3456 | } |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3457 | } |
| 3458 | |
| 3459 | template <class _CharT, class _Traits> |
| 3460 | void |
| 3461 | basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub) |
| 3462 | { |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 3463 | if (!(__flags_ & nosubs)) |
| 3464 | { |
| 3465 | __end_->first() = |
| 3466 | new __end_marked_subexpression<_CharT>(__sub, __end_->first()); |
| 3467 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 3468 | } |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3469 | } |
| 3470 | |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 3471 | template <class _CharT, class _Traits> |
| 3472 | void |
| 3473 | basic_regex<_CharT, _Traits>::__push_r_anchor() |
| 3474 | { |
| 3475 | __end_->first() = new __r_anchor<_CharT>(__end_->first()); |
| 3476 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 3477 | } |
| 3478 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 3479 | template <class _CharT, class _Traits> |
| 3480 | void |
| 3481 | basic_regex<_CharT, _Traits>::__push_match_any() |
| 3482 | { |
| 3483 | __end_->first() = new __match_any<_CharT>(__end_->first()); |
| 3484 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 3485 | } |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 3486 | |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 3487 | template <class _CharT, class _Traits> |
| 3488 | void |
| 3489 | basic_regex<_CharT, _Traits>::__push_back_ref(int __i) |
| 3490 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3491 | if (flags() & icase) |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 3492 | __end_->first() = new __back_ref_icase<_CharT, _Traits> |
| 3493 | (__traits_, __i, __end_->first()); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3494 | else if (flags() & collate) |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 3495 | __end_->first() = new __back_ref_collate<_CharT, _Traits> |
| 3496 | (__traits_, __i, __end_->first()); |
| 3497 | else |
| 3498 | __end_->first() = new __back_ref<_CharT>(__i, __end_->first()); |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 3499 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 3500 | } |
| 3501 | |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3502 | template <class _CharT, class _Traits> |
| 3503 | __bracket_expression<_CharT, _Traits>* |
| 3504 | basic_regex<_CharT, _Traits>::__start_matching_list(bool __negate) |
| 3505 | { |
| 3506 | __bracket_expression<_CharT, _Traits>* __r = |
| 3507 | new __bracket_expression<_CharT, _Traits>(__traits_, __end_->first(), |
| 3508 | __negate, __flags_ & icase, |
| 3509 | __flags_ & collate); |
| 3510 | __end_->first() = __r; |
| 3511 | __end_ = __r; |
| 3512 | return __r; |
| 3513 | } |
| 3514 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3515 | typedef basic_regex<char> regex; |
| 3516 | typedef basic_regex<wchar_t> wregex; |
| 3517 | |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3518 | // sub_match |
| 3519 | |
| 3520 | template <class _BidirectionalIterator> |
| 3521 | class sub_match |
| 3522 | : public pair<_BidirectionalIterator, _BidirectionalIterator> |
| 3523 | { |
| 3524 | public: |
| 3525 | typedef _BidirectionalIterator iterator; |
| 3526 | typedef typename iterator_traits<iterator>::value_type value_type; |
| 3527 | typedef typename iterator_traits<iterator>::difference_type difference_type; |
| 3528 | typedef basic_string<value_type> string_type; |
| 3529 | |
| 3530 | bool matched; |
| 3531 | |
| 3532 | difference_type length() const |
| 3533 | {return matched ? _STD::distance(this->first, this->second) : 0;} |
| 3534 | string_type str() const |
| 3535 | {return matched ? string_type(this->first, this->second) : string_type();} |
| 3536 | operator string_type() const |
| 3537 | {return str();} |
| 3538 | |
| 3539 | int compare(const sub_match& __s) const |
| 3540 | {return str().compare(__s.str());} |
| 3541 | int compare(const string_type& __s) const |
| 3542 | {return str().compare(__s);} |
| 3543 | int compare(const value_type* __s) const |
| 3544 | {return str().compare(__s);} |
| 3545 | }; |
| 3546 | |
| 3547 | typedef sub_match<const char*> csub_match; |
| 3548 | typedef sub_match<const wchar_t*> wcsub_match; |
| 3549 | typedef sub_match<string::const_iterator> ssub_match; |
| 3550 | typedef sub_match<wstring::const_iterator> wssub_match; |
| 3551 | |
| 3552 | template <class _BiIter> |
| 3553 | inline _LIBCPP_INLINE_VISIBILITY |
| 3554 | bool |
| 3555 | operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 3556 | { |
| 3557 | return __x.compare(__y) == 0; |
| 3558 | } |
| 3559 | |
| 3560 | template <class _BiIter> |
| 3561 | inline _LIBCPP_INLINE_VISIBILITY |
| 3562 | bool |
| 3563 | operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 3564 | { |
| 3565 | return !(__x == __y); |
| 3566 | } |
| 3567 | |
| 3568 | template <class _BiIter> |
| 3569 | inline _LIBCPP_INLINE_VISIBILITY |
| 3570 | bool |
| 3571 | operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 3572 | { |
| 3573 | return __x.compare(__y) < 0; |
| 3574 | } |
| 3575 | |
| 3576 | template <class _BiIter> |
| 3577 | inline _LIBCPP_INLINE_VISIBILITY |
| 3578 | bool |
| 3579 | operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 3580 | { |
| 3581 | return !(__y < __x); |
| 3582 | } |
| 3583 | |
| 3584 | template <class _BiIter> |
| 3585 | inline _LIBCPP_INLINE_VISIBILITY |
| 3586 | bool |
| 3587 | operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 3588 | { |
| 3589 | return !(__x < __y); |
| 3590 | } |
| 3591 | |
| 3592 | template <class _BiIter> |
| 3593 | inline _LIBCPP_INLINE_VISIBILITY |
| 3594 | bool |
| 3595 | operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 3596 | { |
| 3597 | return __y < __x; |
| 3598 | } |
| 3599 | |
| 3600 | template <class _BiIter, class _ST, class _SA> |
| 3601 | inline _LIBCPP_INLINE_VISIBILITY |
| 3602 | bool |
| 3603 | operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 3604 | const sub_match<_BiIter>& __y) |
| 3605 | { |
| 3606 | return __y.compare(__x.c_str()) == 0; |
| 3607 | } |
| 3608 | |
| 3609 | template <class _BiIter, class _ST, class _SA> |
| 3610 | inline _LIBCPP_INLINE_VISIBILITY |
| 3611 | bool |
| 3612 | operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 3613 | const sub_match<_BiIter>& __y) |
| 3614 | { |
| 3615 | return !(__x == __y); |
| 3616 | } |
| 3617 | |
| 3618 | template <class _BiIter, class _ST, class _SA> |
| 3619 | inline _LIBCPP_INLINE_VISIBILITY |
| 3620 | bool |
| 3621 | operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 3622 | const sub_match<_BiIter>& __y) |
| 3623 | { |
| 3624 | return __y.compare(__x.c_str()) > 0; |
| 3625 | } |
| 3626 | |
| 3627 | template <class _BiIter, class _ST, class _SA> |
| 3628 | inline _LIBCPP_INLINE_VISIBILITY |
| 3629 | bool |
| 3630 | operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 3631 | const sub_match<_BiIter>& __y) |
| 3632 | { |
| 3633 | return __y < __x; |
| 3634 | } |
| 3635 | |
| 3636 | template <class _BiIter, class _ST, class _SA> |
| 3637 | inline _LIBCPP_INLINE_VISIBILITY |
| 3638 | bool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 3639 | const sub_match<_BiIter>& __y) |
| 3640 | { |
| 3641 | return !(__x < __y); |
| 3642 | } |
| 3643 | |
| 3644 | template <class _BiIter, class _ST, class _SA> |
| 3645 | inline _LIBCPP_INLINE_VISIBILITY |
| 3646 | bool |
| 3647 | operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 3648 | const sub_match<_BiIter>& __y) |
| 3649 | { |
| 3650 | return !(__y < __x); |
| 3651 | } |
| 3652 | |
| 3653 | template <class _BiIter, class _ST, class _SA> |
| 3654 | inline _LIBCPP_INLINE_VISIBILITY |
| 3655 | bool |
| 3656 | operator==(const sub_match<_BiIter>& __x, |
| 3657 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 3658 | { |
| 3659 | return __x.compare(__y.c_str()) == 0; |
| 3660 | } |
| 3661 | |
| 3662 | template <class _BiIter, class _ST, class _SA> |
| 3663 | inline _LIBCPP_INLINE_VISIBILITY |
| 3664 | bool |
| 3665 | operator!=(const sub_match<_BiIter>& __x, |
| 3666 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 3667 | { |
| 3668 | return !(__x == __y); |
| 3669 | } |
| 3670 | |
| 3671 | template <class _BiIter, class _ST, class _SA> |
| 3672 | inline _LIBCPP_INLINE_VISIBILITY |
| 3673 | bool |
| 3674 | operator<(const sub_match<_BiIter>& __x, |
| 3675 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 3676 | { |
| 3677 | return __x.compare(__y.c_str()) < 0; |
| 3678 | } |
| 3679 | |
| 3680 | template <class _BiIter, class _ST, class _SA> |
| 3681 | inline _LIBCPP_INLINE_VISIBILITY |
| 3682 | bool operator>(const sub_match<_BiIter>& __x, |
| 3683 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 3684 | { |
| 3685 | return __y < __x; |
| 3686 | } |
| 3687 | |
| 3688 | template <class _BiIter, class _ST, class _SA> |
| 3689 | inline _LIBCPP_INLINE_VISIBILITY |
| 3690 | bool |
| 3691 | operator>=(const sub_match<_BiIter>& __x, |
| 3692 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 3693 | { |
| 3694 | return !(__x < __y); |
| 3695 | } |
| 3696 | |
| 3697 | template <class _BiIter, class _ST, class _SA> |
| 3698 | inline _LIBCPP_INLINE_VISIBILITY |
| 3699 | bool |
| 3700 | operator<=(const sub_match<_BiIter>& __x, |
| 3701 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 3702 | { |
| 3703 | return !(__y < __x); |
| 3704 | } |
| 3705 | |
| 3706 | template <class _BiIter> |
| 3707 | inline _LIBCPP_INLINE_VISIBILITY |
| 3708 | bool |
| 3709 | operator==(typename iterator_traits<_BiIter>::value_type const* __x, |
| 3710 | const sub_match<_BiIter>& __y) |
| 3711 | { |
| 3712 | return __y.compare(__x) == 0; |
| 3713 | } |
| 3714 | |
| 3715 | template <class _BiIter> |
| 3716 | inline _LIBCPP_INLINE_VISIBILITY |
| 3717 | bool |
| 3718 | operator!=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 3719 | const sub_match<_BiIter>& __y) |
| 3720 | { |
| 3721 | return !(__x == __y); |
| 3722 | } |
| 3723 | |
| 3724 | template <class _BiIter> |
| 3725 | inline _LIBCPP_INLINE_VISIBILITY |
| 3726 | bool |
| 3727 | operator<(typename iterator_traits<_BiIter>::value_type const* __x, |
| 3728 | const sub_match<_BiIter>& __y) |
| 3729 | { |
| 3730 | return __y.compare(__x) > 0; |
| 3731 | } |
| 3732 | |
| 3733 | template <class _BiIter> |
| 3734 | inline _LIBCPP_INLINE_VISIBILITY |
| 3735 | bool |
| 3736 | operator>(typename iterator_traits<_BiIter>::value_type const* __x, |
| 3737 | const sub_match<_BiIter>& __y) |
| 3738 | { |
| 3739 | return __y < __x; |
| 3740 | } |
| 3741 | |
| 3742 | template <class _BiIter> |
| 3743 | inline _LIBCPP_INLINE_VISIBILITY |
| 3744 | bool |
| 3745 | operator>=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 3746 | const sub_match<_BiIter>& __y) |
| 3747 | { |
| 3748 | return !(__x < __y); |
| 3749 | } |
| 3750 | |
| 3751 | template <class _BiIter> |
| 3752 | inline _LIBCPP_INLINE_VISIBILITY |
| 3753 | bool |
| 3754 | operator<=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 3755 | const sub_match<_BiIter>& __y) |
| 3756 | { |
| 3757 | return !(__y < __x); |
| 3758 | } |
| 3759 | |
| 3760 | template <class _BiIter> |
| 3761 | inline _LIBCPP_INLINE_VISIBILITY |
| 3762 | bool |
| 3763 | operator==(const sub_match<_BiIter>& __x, |
| 3764 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 3765 | { |
| 3766 | return __x.compare(__y) == 0; |
| 3767 | } |
| 3768 | |
| 3769 | template <class _BiIter> |
| 3770 | inline _LIBCPP_INLINE_VISIBILITY |
| 3771 | bool |
| 3772 | operator!=(const sub_match<_BiIter>& __x, |
| 3773 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 3774 | { |
| 3775 | return !(__x == __y); |
| 3776 | } |
| 3777 | |
| 3778 | template <class _BiIter> |
| 3779 | inline _LIBCPP_INLINE_VISIBILITY |
| 3780 | bool |
| 3781 | operator<(const sub_match<_BiIter>& __x, |
| 3782 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 3783 | { |
| 3784 | return __x.compare(__y) < 0; |
| 3785 | } |
| 3786 | |
| 3787 | template <class _BiIter> |
| 3788 | inline _LIBCPP_INLINE_VISIBILITY |
| 3789 | bool |
| 3790 | operator>(const sub_match<_BiIter>& __x, |
| 3791 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 3792 | { |
| 3793 | return __y < __x; |
| 3794 | } |
| 3795 | |
| 3796 | template <class _BiIter> |
| 3797 | inline _LIBCPP_INLINE_VISIBILITY |
| 3798 | bool |
| 3799 | operator>=(const sub_match<_BiIter>& __x, |
| 3800 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 3801 | { |
| 3802 | return !(__x < __y); |
| 3803 | } |
| 3804 | |
| 3805 | template <class _BiIter> |
| 3806 | inline _LIBCPP_INLINE_VISIBILITY |
| 3807 | bool |
| 3808 | operator<=(const sub_match<_BiIter>& __x, |
| 3809 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 3810 | { |
| 3811 | return !(__y < __x); |
| 3812 | } |
| 3813 | |
| 3814 | template <class _BiIter> |
| 3815 | inline _LIBCPP_INLINE_VISIBILITY |
| 3816 | bool |
| 3817 | operator==(typename iterator_traits<_BiIter>::value_type const& __x, |
| 3818 | const sub_match<_BiIter>& __y) |
| 3819 | { |
| 3820 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 3821 | return __y.compare(string_type(1, __x)) == 0; |
| 3822 | } |
| 3823 | |
| 3824 | template <class _BiIter> |
| 3825 | inline _LIBCPP_INLINE_VISIBILITY |
| 3826 | bool |
| 3827 | operator!=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 3828 | const sub_match<_BiIter>& __y) |
| 3829 | { |
| 3830 | return !(__x == __y); |
| 3831 | } |
| 3832 | |
| 3833 | template <class _BiIter> |
| 3834 | inline _LIBCPP_INLINE_VISIBILITY |
| 3835 | bool |
| 3836 | operator<(typename iterator_traits<_BiIter>::value_type const& __x, |
| 3837 | const sub_match<_BiIter>& __y) |
| 3838 | { |
| 3839 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 3840 | return __y.compare(string_type(1, __x)) > 0; |
| 3841 | } |
| 3842 | |
| 3843 | template <class _BiIter> |
| 3844 | inline _LIBCPP_INLINE_VISIBILITY |
| 3845 | bool |
| 3846 | operator>(typename iterator_traits<_BiIter>::value_type const& __x, |
| 3847 | const sub_match<_BiIter>& __y) |
| 3848 | { |
| 3849 | return __y < __x; |
| 3850 | } |
| 3851 | |
| 3852 | template <class _BiIter> |
| 3853 | inline _LIBCPP_INLINE_VISIBILITY |
| 3854 | bool |
| 3855 | operator>=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 3856 | const sub_match<_BiIter>& __y) |
| 3857 | { |
| 3858 | return !(__x < __y); |
| 3859 | } |
| 3860 | |
| 3861 | template <class _BiIter> |
| 3862 | inline _LIBCPP_INLINE_VISIBILITY |
| 3863 | bool |
| 3864 | operator<=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 3865 | const sub_match<_BiIter>& __y) |
| 3866 | { |
| 3867 | return !(__y < __x); |
| 3868 | } |
| 3869 | |
| 3870 | template <class _BiIter> |
| 3871 | inline _LIBCPP_INLINE_VISIBILITY |
| 3872 | bool |
| 3873 | operator==(const sub_match<_BiIter>& __x, |
| 3874 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 3875 | { |
| 3876 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 3877 | return __x.compare(string_type(1, __y)) == 0; |
| 3878 | } |
| 3879 | |
| 3880 | template <class _BiIter> |
| 3881 | inline _LIBCPP_INLINE_VISIBILITY |
| 3882 | bool |
| 3883 | operator!=(const sub_match<_BiIter>& __x, |
| 3884 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 3885 | { |
| 3886 | return !(__x == __y); |
| 3887 | } |
| 3888 | |
| 3889 | template <class _BiIter> |
| 3890 | inline _LIBCPP_INLINE_VISIBILITY |
| 3891 | bool |
| 3892 | operator<(const sub_match<_BiIter>& __x, |
| 3893 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 3894 | { |
| 3895 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 3896 | return __x.compare(string_type(1, __y)) < 0; |
| 3897 | } |
| 3898 | |
| 3899 | template <class _BiIter> |
| 3900 | inline _LIBCPP_INLINE_VISIBILITY |
| 3901 | bool |
| 3902 | operator>(const sub_match<_BiIter>& __x, |
| 3903 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 3904 | { |
| 3905 | return __y < __x; |
| 3906 | } |
| 3907 | |
| 3908 | template <class _BiIter> |
| 3909 | inline _LIBCPP_INLINE_VISIBILITY |
| 3910 | bool |
| 3911 | operator>=(const sub_match<_BiIter>& __x, |
| 3912 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 3913 | { |
| 3914 | return !(__x < __y); |
| 3915 | } |
| 3916 | |
| 3917 | template <class _BiIter> |
| 3918 | inline _LIBCPP_INLINE_VISIBILITY |
| 3919 | bool |
| 3920 | operator<=(const sub_match<_BiIter>& __x, |
| 3921 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 3922 | { |
| 3923 | return !(__y < __x); |
| 3924 | } |
| 3925 | |
| 3926 | template <class _CharT, class _ST, class _BiIter> |
| 3927 | inline _LIBCPP_INLINE_VISIBILITY |
| 3928 | basic_ostream<_CharT, _ST>& |
| 3929 | operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m) |
| 3930 | { |
| 3931 | return __os << __m.str(); |
| 3932 | } |
| 3933 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 3934 | template <class _BidirectionalIterator, |
| 3935 | class _Allocator = allocator<sub_match<_BidirectionalIterator> > > |
| 3936 | class match_results |
| 3937 | { |
| 3938 | public: |
| 3939 | typedef _Allocator allocator_type; |
| 3940 | typedef sub_match<_BidirectionalIterator> value_type; |
| 3941 | private: |
| 3942 | typedef vector<value_type, allocator_type> __container_type; |
| 3943 | |
| 3944 | __container_type __matches_; |
| 3945 | value_type __unmatched_; |
| 3946 | value_type __prefix_; |
| 3947 | value_type __suffix_; |
| 3948 | public: |
| 3949 | typedef const value_type& const_reference; |
| 3950 | typedef const_reference reference; |
| 3951 | typedef typename __container_type::const_iterator const_iterator; |
| 3952 | typedef const_iterator iterator; |
| 3953 | typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; |
| 3954 | typedef typename allocator_traits<allocator_type>::size_type size_type; |
| 3955 | typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type; |
| 3956 | typedef basic_string<char_type> string_type; |
| 3957 | |
| 3958 | // construct/copy/destroy: |
| 3959 | explicit match_results(const allocator_type& __a = allocator_type()); |
| 3960 | // match_results(const match_results&) = default; |
| 3961 | // match_results& operator=(const match_results&) = default; |
| 3962 | #ifdef _LIBCPP_MOVE |
| 3963 | // match_results(match_results&& __m) = default; |
| 3964 | // match_results& operator=(match_results&& __m) = default; |
| 3965 | #endif |
| 3966 | // ~match_results() = default; |
| 3967 | |
| 3968 | // size: |
| 3969 | size_type size() const {return __matches_.size();} |
| 3970 | size_type max_size() const {return __matches_.max_size();} |
| 3971 | bool empty() const {return size() == 0;} |
| 3972 | |
| 3973 | // element access: |
| 3974 | difference_type length(size_type __sub = 0) const |
| 3975 | {return (*this)[__sub].length();} |
| 3976 | difference_type position(size_type __sub = 0) const |
| 3977 | {return _STD::distance(__prefix_.first, (*this)[__sub].first);} |
| 3978 | string_type str(size_type __sub = 0) const |
| 3979 | {return (*this)[__sub].str();} |
| 3980 | const_reference operator[](size_type __n) const |
| 3981 | {return __n < __matches_.size() ? __matches_[__n] : __unmatched_;} |
| 3982 | |
| 3983 | const_reference prefix() const {return __prefix_;} |
| 3984 | const_reference suffix() const {return __suffix_;} |
| 3985 | |
| 3986 | const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin() + 1;} |
| 3987 | const_iterator end() const {return __matches_.end();} |
| 3988 | const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin() + 1;} |
| 3989 | const_iterator cend() const {return __matches_.end();} |
| 3990 | |
| 3991 | // format: |
| 3992 | template <class _OutputIter> |
| 3993 | _OutputIter |
| 3994 | format(_OutputIter __out, const char_type* __fmt_first, |
| 3995 | const char_type* __fmt_last, |
| 3996 | regex_constants::match_flag_type __flags = regex_constants::format_default) const; |
| 3997 | template <class _OutputIter, class _ST, class _SA> |
| 3998 | _OutputIter |
| 3999 | format(_OutputIter __out, const basic_string<char_type, _ST, _SA>& __fmt, |
| 4000 | regex_constants::match_flag_type __flags = regex_constants::format_default) const; |
| 4001 | template <class _ST, class _SA> |
| 4002 | basic_string<char_type, _ST, _SA> |
| 4003 | format(const basic_string<char_type, _ST, _SA>& __fmt, |
| 4004 | regex_constants::match_flag_type __flags = regex_constants::format_default) const; |
| 4005 | string_type |
| 4006 | format(const char_type* __fmt, |
| 4007 | regex_constants::match_flag_type __flags = regex_constants::format_default) const; |
| 4008 | |
| 4009 | // allocator: |
| 4010 | allocator_type get_allocator() const {return __matches_.get_allocator();} |
| 4011 | |
| 4012 | // swap: |
| 4013 | void swap(match_results& __m); |
| 4014 | |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 4015 | template <class _B, class _A> |
| 4016 | void __assign(_BidirectionalIterator __f, _BidirectionalIterator __l, |
| 4017 | const match_results<_B, _A>& __m) |
| 4018 | { |
| 4019 | _B __mf = __m.prefix().first; |
| 4020 | __matches_.resize(__m.size()); |
| 4021 | for (size_type __i = 0; __i < __matches_.size(); ++__i) |
| 4022 | { |
| 4023 | __matches_[__i].first = next(__f, _STD::distance(__mf, __m[__i].first)); |
| 4024 | __matches_[__i].second = next(__f, _STD::distance(__mf, __m[__i].second)); |
| 4025 | __matches_[__i].matched = __m[__i].matched; |
| 4026 | } |
| 4027 | __unmatched_.first = __l; |
| 4028 | __unmatched_.second = __l; |
| 4029 | __unmatched_.matched = false; |
| 4030 | __prefix_.first = next(__f, _STD::distance(__mf, __m.prefix().first)); |
| 4031 | __prefix_.second = next(__f, _STD::distance(__mf, __m.prefix().second)); |
| 4032 | __prefix_.matched = __m.prefix().matched; |
| 4033 | __suffix_.first = next(__f, _STD::distance(__mf, __m.suffix().first)); |
| 4034 | __suffix_.second = next(__f, _STD::distance(__mf, __m.suffix().second)); |
| 4035 | __suffix_.matched = __m.suffix().matched; |
| 4036 | } |
| 4037 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 4038 | private: |
| 4039 | void __init(unsigned __s, |
| 4040 | _BidirectionalIterator __f, _BidirectionalIterator __l); |
| 4041 | |
| 4042 | template <class, class> friend class basic_regex; |
| 4043 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 4044 | template <class _B, class _A, class _C, class _T> |
| 4045 | friend |
| 4046 | bool |
| 4047 | regex_match(_B, _B, match_results<_B, _A>&, const basic_regex<_C, _T>&, |
| 4048 | regex_constants::match_flag_type); |
| 4049 | }; |
| 4050 | |
| 4051 | template <class _BidirectionalIterator, class _Allocator> |
| 4052 | match_results<_BidirectionalIterator, _Allocator>::match_results( |
| 4053 | const allocator_type& __a) |
| 4054 | : __matches_(__a), |
| 4055 | __unmatched_(), |
| 4056 | __prefix_(), |
| 4057 | __suffix_() |
| 4058 | { |
| 4059 | } |
| 4060 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 4061 | template <class _BidirectionalIterator, class _Allocator> |
| 4062 | void |
| 4063 | match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s, |
| 4064 | _BidirectionalIterator __f, _BidirectionalIterator __l) |
| 4065 | { |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 4066 | __unmatched_.first = __l; |
| 4067 | __unmatched_.second = __l; |
| 4068 | __unmatched_.matched = false; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4069 | __matches_.assign(__s, __unmatched_); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 4070 | __prefix_.first = __f; |
| 4071 | __prefix_.second = __f; |
| 4072 | __prefix_.matched = false; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 4073 | __suffix_ = __unmatched_; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 4074 | } |
| 4075 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 4076 | typedef match_results<const char*> cmatch; |
| 4077 | typedef match_results<const wchar_t*> wcmatch; |
| 4078 | typedef match_results<string::const_iterator> smatch; |
| 4079 | typedef match_results<wstring::const_iterator> wsmatch; |
| 4080 | |
| 4081 | template <class _BidirectionalIterator, class _Allocator> |
| 4082 | bool |
| 4083 | operator==(const match_results<_BidirectionalIterator, _Allocator>& __x, |
| 4084 | const match_results<_BidirectionalIterator, _Allocator>& __y); |
| 4085 | |
| 4086 | template <class _BidirectionalIterator, class _Allocator> |
| 4087 | bool |
| 4088 | operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x, |
| 4089 | const match_results<_BidirectionalIterator, _Allocator>& __y); |
| 4090 | |
| 4091 | template <class _BidirectionalIterator, class _Allocator> |
| 4092 | void |
| 4093 | swap(match_results<_BidirectionalIterator, _Allocator>& __x, |
| 4094 | match_results<_BidirectionalIterator, _Allocator>& __y); |
| 4095 | |
| 4096 | // regex_search |
| 4097 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 4098 | template <class _CharT, class _Traits> |
| 4099 | template <class _BidirectionalIterator, class _Allocator> |
| 4100 | bool |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4101 | basic_regex<_CharT, _Traits>::__match_at_start_ecma( |
| 4102 | _BidirectionalIterator __first, _BidirectionalIterator __last, |
| 4103 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 4104 | regex_constants::match_flag_type __flags) const |
| 4105 | { |
| 4106 | return false; |
| 4107 | } |
| 4108 | |
| 4109 | template <class _CharT, class _Traits> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 4110 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4111 | bool |
| 4112 | basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs( |
| 4113 | const _CharT* __first, const _CharT* __last, |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 4114 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4115 | vector<size_t>& __lc, |
| 4116 | regex_constants::match_flag_type __flags) const |
| 4117 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4118 | deque<__state> __states; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 4119 | ptrdiff_t __highest_j = 0; |
| 4120 | ptrdiff_t _N = _STD::distance(__first, __last); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4121 | __node* __st = __start_.get(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4122 | if (__st) |
| 4123 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4124 | __states.push_back(__state()); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4125 | __states.back().__do_ = 0; |
| 4126 | __states.back().__first_ = __first; |
| 4127 | __states.back().__current_ = __first; |
| 4128 | __states.back().__last_ = __last; |
| 4129 | __states.back().__loop_data_.resize(__loop_count()); |
| 4130 | __states.back().__node_ = __st; |
| 4131 | __states.back().__flags_ = __flags; |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 4132 | bool __matched = false; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4133 | do |
| 4134 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4135 | __state& __s = __states.back(); |
| 4136 | if (__s.__node_) |
| 4137 | __s.__node_->__exec(__s); |
| 4138 | switch (__s.__do_) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4139 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4140 | case __state::__end_state: |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 4141 | if (__highest_j < __s.__current_ - __s.__first_) |
| 4142 | { |
| 4143 | __highest_j = __s.__current_ - __s.__first_; |
| 4144 | __matched = true; |
| 4145 | } |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4146 | if (__highest_j == _N) |
| 4147 | __states.clear(); |
| 4148 | else |
| 4149 | __states.pop_back(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4150 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4151 | case __state::__consume_input: |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4152 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4153 | case __state::__accept_and_consume: |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4154 | __states.push_front(_STD::move(__s)); |
| 4155 | __states.pop_back(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4156 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4157 | case __state::__repeat: |
| 4158 | case __state::__accept_but_not_consume: |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4159 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4160 | case __state::__split: |
| 4161 | { |
| 4162 | __state __snext = __s; |
| 4163 | __s.__node_->__exec_split(true, __s); |
| 4164 | __snext.__node_->__exec_split(false, __snext); |
| 4165 | __states.push_back(_STD::move(__snext)); |
| 4166 | } |
| 4167 | break; |
| 4168 | case __state::__reject: |
| 4169 | __states.pop_back(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4170 | break; |
| 4171 | default: |
| 4172 | throw regex_error(regex_constants::error_temp); |
| 4173 | break; |
| 4174 | } |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4175 | } while (!__states.empty()); |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 4176 | if (__matched) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4177 | { |
| 4178 | __m.__matches_[0].first = __first; |
| 4179 | __m.__matches_[0].second = _STD::next(__first, __highest_j); |
| 4180 | __m.__matches_[0].matched = true; |
| 4181 | return true; |
| 4182 | } |
| 4183 | } |
| 4184 | return false; |
| 4185 | } |
| 4186 | |
| 4187 | template <class _CharT, class _Traits> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 4188 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4189 | bool |
| 4190 | basic_regex<_CharT, _Traits>::__match_at_start_posix_subs( |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 4191 | const _CharT* __first, const _CharT* __last, |
| 4192 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 4193 | vector<size_t>& __lc, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4194 | regex_constants::match_flag_type __flags) const |
| 4195 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4196 | vector<__state> __states; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 4197 | vector<const _CharT*> __current_stack; |
| 4198 | vector<sub_match<const _CharT*> > __saved_matches; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4199 | __state __best_state; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 4200 | ptrdiff_t __j = 0; |
| 4201 | ptrdiff_t __highest_j = 0; |
| 4202 | ptrdiff_t _N = _STD::distance(__first, __last); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4203 | __node* __st = __start_.get(); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 4204 | if (__st) |
| 4205 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4206 | __states.push_back(__state()); |
| 4207 | __states.back().__do_ = 0; |
| 4208 | __states.back().__first_ = __first; |
| 4209 | __states.back().__current_ = __first; |
| 4210 | __states.back().__last_ = __last; |
| 4211 | __states.back().__sub_matches_.resize(mark_count()); |
| 4212 | __states.back().__loop_data_.resize(__loop_count()); |
| 4213 | __states.back().__node_ = __st; |
| 4214 | __states.back().__flags_ = __flags; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 4215 | const _CharT* __current = __first; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4216 | bool __matched = false; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 4217 | do |
| 4218 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4219 | __state& __s = __states.back(); |
| 4220 | if (__s.__node_) |
| 4221 | __s.__node_->__exec(__s); |
| 4222 | switch (__s.__do_) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 4223 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4224 | case __state::__end_state: |
| 4225 | if (__j == 0 || __highest_j < __j) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 4226 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4227 | __matched = true; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 4228 | __highest_j = __j; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4229 | __best_state = __s; |
| 4230 | if (__highest_j == _N || __highest_j == 0) |
| 4231 | __states.clear(); |
| 4232 | else |
| 4233 | __states.pop_back(); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 4234 | } |
| 4235 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4236 | case __state::__accept_and_consume: |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4237 | __j += __s.__current_ - __current; |
| 4238 | __current = __s.__current_; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 4239 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4240 | case __state::__repeat: |
| 4241 | case __state::__accept_but_not_consume: |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 4242 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4243 | case __state::__split: |
| 4244 | { |
| 4245 | __state __snext = __s; |
| 4246 | __s.__node_->__exec_split(true, __s); |
| 4247 | __snext.__node_->__exec_split(false, __snext); |
| 4248 | __states.push_back(_STD::move(__snext)); |
| 4249 | } |
| 4250 | break; |
| 4251 | case __state::__reject: |
| 4252 | __states.pop_back(); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 4253 | break; |
| 4254 | default: |
| 4255 | throw regex_error(regex_constants::error_temp); |
| 4256 | break; |
| 4257 | } |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4258 | } while (!__states.empty()); |
| 4259 | if (__matched) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 4260 | { |
| 4261 | __m.__matches_[0].first = __first; |
| 4262 | __m.__matches_[0].second = _STD::next(__first, __highest_j); |
| 4263 | __m.__matches_[0].matched = true; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4264 | for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i) |
| 4265 | __m.__matches_[__i+1] = __best_state.__sub_matches_[__i]; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 4266 | return true; |
| 4267 | } |
| 4268 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4269 | return false; |
| 4270 | } |
| 4271 | |
| 4272 | template <class _CharT, class _Traits> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 4273 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4274 | bool |
| 4275 | basic_regex<_CharT, _Traits>::__match_at_start( |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 4276 | const _CharT* __first, const _CharT* __last, |
| 4277 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4278 | vector<size_t>& __lc, |
| 4279 | regex_constants::match_flag_type __flags) const |
| 4280 | { |
| 4281 | if (__flags_ & ECMAScript) |
| 4282 | return __match_at_start_ecma(__first, __last, __m, __flags); |
| 4283 | if (mark_count() == 0) |
| 4284 | return __match_at_start_posix_nosubs(__first, __last, __m, __lc, __flags); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 4285 | return __match_at_start_posix_subs(__first, __last, __m, __lc, __flags); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4286 | } |
| 4287 | |
| 4288 | template <class _CharT, class _Traits> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 4289 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4290 | bool |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 4291 | basic_regex<_CharT, _Traits>::__search( |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 4292 | const _CharT* __first, const _CharT* __last, |
| 4293 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 4294 | regex_constants::match_flag_type __flags) const |
| 4295 | { |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4296 | if (__left_anchor_) |
| 4297 | __flags |= regex_constants::match_continuous; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4298 | __m.__init(1 + mark_count(), __first, __last); |
| 4299 | vector<size_t> __lc(__loop_count()); |
| 4300 | if (__match_at_start(__first, __last, __m, __lc, __flags)) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 4301 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4302 | __m.__prefix_.second = __m[0].first; |
| 4303 | __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; |
| 4304 | __m.__suffix_.first = __m[0].second; |
| 4305 | __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; |
| 4306 | return true; |
| 4307 | } |
| 4308 | if (!(__flags & regex_constants::match_continuous)) |
| 4309 | { |
| 4310 | __m.__matches_.assign(__m.size(), __m.__unmatched_); |
| 4311 | for (++__first; __first != __last; ++__first) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 4312 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4313 | if (__match_at_start(__first, __last, __m, __lc, __flags)) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 4314 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4315 | __m.__prefix_.second = __m[0].first; |
| 4316 | __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; |
| 4317 | __m.__suffix_.first = __m[0].second; |
| 4318 | __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; |
| 4319 | return true; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 4320 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4321 | __m.__matches_.assign(__m.size(), __m.__unmatched_); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 4322 | } |
| 4323 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4324 | __m.__matches_.clear(); |
| 4325 | return false; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 4326 | } |
| 4327 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 4328 | template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 4329 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 4330 | bool |
| 4331 | regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 4332 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 4333 | const basic_regex<_CharT, _Traits>& __e, |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 4334 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 4335 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 4336 | basic_string<_CharT> __s(__first, __last); |
| 4337 | match_results<const _CharT*> __mc; |
| 4338 | bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
| 4339 | __m.__assign(__first, __last, __mc); |
| 4340 | return __r; |
| 4341 | } |
| 4342 | |
| 4343 | template <class _Allocator, class _CharT, class _Traits> |
| 4344 | inline _LIBCPP_INLINE_VISIBILITY |
| 4345 | bool |
| 4346 | regex_search(const _CharT* __first, const _CharT* __last, |
| 4347 | match_results<const _CharT*, _Allocator>& __m, |
| 4348 | const basic_regex<_CharT, _Traits>& __e, |
| 4349 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 4350 | { |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 4351 | return __e.__search(__first, __last, __m, __flags); |
| 4352 | } |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 4353 | |
| 4354 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 4355 | inline _LIBCPP_INLINE_VISIBILITY |
| 4356 | bool |
| 4357 | regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 4358 | const basic_regex<_CharT, _Traits>& __e, |
| 4359 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 4360 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 4361 | basic_string<_CharT> __s(__first, __last); |
| 4362 | match_results<const _CharT*> __mc; |
| 4363 | return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
| 4364 | } |
| 4365 | |
| 4366 | template <class _CharT, class _Traits> |
| 4367 | inline _LIBCPP_INLINE_VISIBILITY |
| 4368 | bool |
| 4369 | regex_search(const _CharT* __first, const _CharT* __last, |
| 4370 | const basic_regex<_CharT, _Traits>& __e, |
| 4371 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 4372 | { |
| 4373 | match_results<const _CharT*> __mc; |
| 4374 | return __e.__search(__first, __last, __mc, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 4375 | } |
| 4376 | |
| 4377 | template <class _CharT, class _Allocator, class _Traits> |
| 4378 | inline _LIBCPP_INLINE_VISIBILITY |
| 4379 | bool |
| 4380 | regex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, |
| 4381 | const basic_regex<_CharT, _Traits>& __e, |
| 4382 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 4383 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 4384 | return __e.__search(__str, __str + _Traits::length(__str), __m, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 4385 | } |
| 4386 | |
| 4387 | template <class _CharT, class _Traits> |
| 4388 | inline _LIBCPP_INLINE_VISIBILITY |
| 4389 | bool |
| 4390 | regex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, |
| 4391 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 4392 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 4393 | match_results<const _CharT*> __m; |
| 4394 | return _STD::regex_search(__str, __m, __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 4395 | } |
| 4396 | |
| 4397 | template <class _ST, class _SA, class _CharT, class _Traits> |
| 4398 | inline _LIBCPP_INLINE_VISIBILITY |
| 4399 | bool |
| 4400 | regex_search(const basic_string<_CharT, _ST, _SA>& __s, |
| 4401 | const basic_regex<_CharT, _Traits>& __e, |
| 4402 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 4403 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 4404 | match_results<const _CharT*> __mc; |
| 4405 | return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 4406 | } |
| 4407 | |
| 4408 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 4409 | inline _LIBCPP_INLINE_VISIBILITY |
| 4410 | bool |
| 4411 | regex_search(const basic_string<_CharT, _ST, _SA>& __s, |
| 4412 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 4413 | const basic_regex<_CharT, _Traits>& __e, |
| 4414 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 4415 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 4416 | match_results<const _CharT*> __mc; |
| 4417 | bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
| 4418 | __m.__assign(__s.begin(), __s.end(), __mc); |
| 4419 | return __r; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 4420 | } |
| 4421 | |
| 4422 | // regex_match |
| 4423 | |
| 4424 | template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> |
| 4425 | bool |
| 4426 | regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 4427 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 4428 | const basic_regex<_CharT, _Traits>& __e, |
| 4429 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 4430 | { |
| 4431 | bool __r = _STD::regex_search(__first, __last, __m, __e, |
| 4432 | __flags | regex_constants::match_continuous); |
| 4433 | if (__r) |
| 4434 | { |
| 4435 | __r = !__m.suffix().matched; |
| 4436 | if (!__r) |
| 4437 | __m.__matches_.clear(); |
| 4438 | } |
| 4439 | return __r; |
| 4440 | } |
| 4441 | |
| 4442 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 4443 | inline _LIBCPP_INLINE_VISIBILITY |
| 4444 | bool |
| 4445 | regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 4446 | const basic_regex<_CharT, _Traits>& __e, |
| 4447 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 4448 | { |
| 4449 | match_results<_BidirectionalIterator> __m; |
| 4450 | return _STD::regex_match(__first, __last, __m, __e, __flags); |
| 4451 | } |
| 4452 | |
| 4453 | template <class _CharT, class _Allocator, class _Traits> |
| 4454 | inline _LIBCPP_INLINE_VISIBILITY |
| 4455 | bool |
| 4456 | regex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, |
| 4457 | const basic_regex<_CharT, _Traits>& __e, |
| 4458 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 4459 | { |
| 4460 | return _STD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags); |
| 4461 | } |
| 4462 | |
| 4463 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 4464 | inline _LIBCPP_INLINE_VISIBILITY |
| 4465 | bool |
| 4466 | regex_match(const basic_string<_CharT, _ST, _SA>& __s, |
| 4467 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 4468 | const basic_regex<_CharT, _Traits>& __e, |
| 4469 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 4470 | { |
| 4471 | return _STD::regex_match(__s.begin(), __s.end(), __m, __e, __flags); |
| 4472 | } |
| 4473 | |
| 4474 | template <class _CharT, class _Traits> |
| 4475 | inline _LIBCPP_INLINE_VISIBILITY |
| 4476 | bool |
| 4477 | regex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, |
| 4478 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 4479 | { |
| 4480 | return _STD::regex_match(__str, __str + _Traits::length(__str), __e, __flags); |
| 4481 | } |
| 4482 | |
| 4483 | template <class _ST, class _SA, class _CharT, class _Traits> |
| 4484 | inline _LIBCPP_INLINE_VISIBILITY |
| 4485 | bool |
| 4486 | regex_match(const basic_string<_CharT, _ST, _SA>& __s, |
| 4487 | const basic_regex<_CharT, _Traits>& __e, |
| 4488 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 4489 | { |
| 4490 | return _STD::regex_match(__s.begin(), __s.end(), __e, __flags); |
| 4491 | } |
| 4492 | |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 4493 | _LIBCPP_END_NAMESPACE_STD |
| 4494 | |
| 4495 | #endif // _LIBCPP_REGEX |