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, |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame^] | 750 | ECMAScript = 0, |
| 751 | basic = 1 << 4, |
| 752 | extended = 1 << 5, |
| 753 | awk = 1 << 6, |
| 754 | grep = 1 << 7, |
| 755 | egrep = 1 << 8 |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 756 | }; |
| 757 | |
| 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, |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame^] | 910 | __re_err_grammar, |
| 911 | __re_err_empty, |
| 912 | __re_err_unknown |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 913 | }; |
| 914 | |
| 915 | } // regex_constants |
| 916 | |
| 917 | class _LIBCPP_EXCEPTION_ABI regex_error |
| 918 | : public runtime_error |
| 919 | { |
| 920 | regex_constants::error_type __code_; |
| 921 | public: |
| 922 | explicit regex_error(regex_constants::error_type __ecode); |
| 923 | virtual ~regex_error() throw(); |
| 924 | regex_constants::error_type code() const {return __code_;} |
| 925 | }; |
| 926 | |
| 927 | template <class _CharT> |
| 928 | struct regex_traits |
| 929 | { |
| 930 | public: |
| 931 | typedef _CharT char_type; |
| 932 | typedef basic_string<char_type> string_type; |
| 933 | typedef locale locale_type; |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 934 | typedef ctype_base::mask char_class_type; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 935 | |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 936 | static const char_class_type __regex_word = 0x80; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 937 | private: |
| 938 | locale __loc_; |
| 939 | const ctype<char_type>* __ct_; |
| 940 | const collate<char_type>* __col_; |
| 941 | |
| 942 | public: |
| 943 | regex_traits(); |
| 944 | |
| 945 | static size_t length(const char_type* __p) |
| 946 | {return char_traits<char_type>::length(__p);} |
| 947 | char_type translate(char_type __c) const {return __c;} |
| 948 | char_type translate_nocase(char_type __c) const; |
| 949 | template <class _ForwardIterator> |
| 950 | string_type |
| 951 | transform(_ForwardIterator __f, _ForwardIterator __l) const; |
| 952 | template <class _ForwardIterator> |
| 953 | string_type |
| 954 | transform_primary( _ForwardIterator __f, _ForwardIterator __l) const |
| 955 | {return __transform_primary(__f, __l, char_type());} |
| 956 | template <class _ForwardIterator> |
| 957 | string_type |
| 958 | lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const |
| 959 | {return __lookup_collatename(__f, __l, char_type());} |
| 960 | template <class _ForwardIterator> |
| 961 | char_class_type |
| 962 | lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 963 | bool __icase = false) const |
| 964 | {return __lookup_classname(__f, __l, __icase, char_type());} |
| 965 | bool isctype(char_type __c, char_class_type __m) const; |
| 966 | int value(char_type __ch, int __radix) const |
| 967 | {return __value(__ch, __radix);} |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 968 | locale_type imbue(locale_type __l); |
| 969 | locale_type getloc()const {return __loc_;} |
| 970 | |
| 971 | private: |
| 972 | void __init(); |
| 973 | |
| 974 | template <class _ForwardIterator> |
| 975 | string_type |
| 976 | __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const; |
| 977 | template <class _ForwardIterator> |
| 978 | string_type |
| 979 | __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; |
| 980 | |
| 981 | template <class _ForwardIterator> |
| 982 | string_type |
| 983 | __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const; |
| 984 | template <class _ForwardIterator> |
| 985 | string_type |
| 986 | __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 987 | |
| 988 | template <class _ForwardIterator> |
| 989 | char_class_type |
| 990 | __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
| 991 | bool __icase, char) const; |
| 992 | template <class _ForwardIterator> |
| 993 | char_class_type |
| 994 | __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
| 995 | bool __icase, wchar_t) const; |
| 996 | |
| 997 | static int __value(unsigned char __ch, int __radix); |
| 998 | int __value(char __ch, int __radix) const |
| 999 | {return __value(static_cast<unsigned char>(__ch), __radix);} |
| 1000 | int __value(wchar_t __ch, int __radix) const; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1001 | }; |
| 1002 | |
| 1003 | template <class _CharT> |
| 1004 | regex_traits<_CharT>::regex_traits() |
| 1005 | { |
| 1006 | __init(); |
| 1007 | } |
| 1008 | |
| 1009 | template <class _CharT> |
| 1010 | typename regex_traits<_CharT>::char_type |
| 1011 | regex_traits<_CharT>::translate_nocase(char_type __c) const |
| 1012 | { |
| 1013 | return __ct_->tolower(__c); |
| 1014 | } |
| 1015 | |
| 1016 | template <class _CharT> |
| 1017 | template <class _ForwardIterator> |
| 1018 | typename regex_traits<_CharT>::string_type |
| 1019 | regex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const |
| 1020 | { |
| 1021 | string_type __s(__f, __l); |
| 1022 | return __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1023 | } |
| 1024 | |
| 1025 | template <class _CharT> |
| 1026 | void |
| 1027 | regex_traits<_CharT>::__init() |
| 1028 | { |
| 1029 | __ct_ = &use_facet<ctype<char_type> >(__loc_); |
| 1030 | __col_ = &use_facet<collate<char_type> >(__loc_); |
| 1031 | } |
| 1032 | |
| 1033 | template <class _CharT> |
| 1034 | typename regex_traits<_CharT>::locale_type |
| 1035 | regex_traits<_CharT>::imbue(locale_type __l) |
| 1036 | { |
| 1037 | locale __r = __loc_; |
| 1038 | __loc_ = __l; |
| 1039 | __init(); |
| 1040 | return __r; |
| 1041 | } |
| 1042 | |
| 1043 | // transform_primary is very FreeBSD-specific |
| 1044 | |
| 1045 | template <class _CharT> |
| 1046 | template <class _ForwardIterator> |
| 1047 | typename regex_traits<_CharT>::string_type |
| 1048 | regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, |
| 1049 | _ForwardIterator __l, char) const |
| 1050 | { |
| 1051 | const string_type __s(__f, __l); |
| 1052 | string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1053 | switch (__d.size()) |
| 1054 | { |
| 1055 | case 1: |
| 1056 | break; |
| 1057 | case 12: |
| 1058 | __d[11] = __d[3]; |
| 1059 | break; |
| 1060 | default: |
| 1061 | __d.clear(); |
| 1062 | break; |
| 1063 | } |
| 1064 | return __d; |
| 1065 | } |
| 1066 | |
| 1067 | template <class _CharT> |
| 1068 | template <class _ForwardIterator> |
| 1069 | typename regex_traits<_CharT>::string_type |
| 1070 | regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, |
| 1071 | _ForwardIterator __l, wchar_t) const |
| 1072 | { |
| 1073 | const string_type __s(__f, __l); |
| 1074 | string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1075 | switch (__d.size()) |
| 1076 | { |
| 1077 | case 1: |
| 1078 | break; |
| 1079 | case 3: |
| 1080 | __d[2] = __d[0]; |
| 1081 | break; |
| 1082 | default: |
| 1083 | __d.clear(); |
| 1084 | break; |
| 1085 | } |
| 1086 | return __d; |
| 1087 | } |
| 1088 | |
| 1089 | // lookup_collatename is very FreeBSD-specific |
| 1090 | |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1091 | string __get_collation_name(const char* __s); |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1092 | |
| 1093 | template <class _CharT> |
| 1094 | template <class _ForwardIterator> |
| 1095 | typename regex_traits<_CharT>::string_type |
| 1096 | regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, |
| 1097 | _ForwardIterator __l, char) const |
| 1098 | { |
| 1099 | string_type __s(__f, __l); |
| 1100 | string_type __r; |
| 1101 | if (!__s.empty()) |
| 1102 | { |
| 1103 | __r = __get_collation_name(__s.c_str()); |
| 1104 | if (__r.empty() && __s.size() <= 2) |
| 1105 | { |
| 1106 | __r = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1107 | if (__r.size() == 1 || __r.size() == 12) |
| 1108 | __r = __s; |
| 1109 | else |
| 1110 | __r.clear(); |
| 1111 | } |
| 1112 | } |
| 1113 | return __r; |
| 1114 | } |
| 1115 | |
| 1116 | template <class _CharT> |
| 1117 | template <class _ForwardIterator> |
| 1118 | typename regex_traits<_CharT>::string_type |
| 1119 | regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, |
| 1120 | _ForwardIterator __l, wchar_t) const |
| 1121 | { |
| 1122 | string_type __s(__f, __l); |
| 1123 | string __n; |
| 1124 | __n.reserve(__s.size()); |
| 1125 | for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); |
| 1126 | __i != __e; ++__i) |
| 1127 | { |
| 1128 | if (static_cast<unsigned>(*__i) >= 127) |
| 1129 | return string_type(); |
| 1130 | __n.push_back(char(*__i)); |
| 1131 | } |
| 1132 | string_type __r; |
| 1133 | if (!__s.empty()) |
| 1134 | { |
| 1135 | __n = __get_collation_name(__n.c_str()); |
| 1136 | if (!__n.empty()) |
| 1137 | __r.assign(__n.begin(), __n.end()); |
| 1138 | else if (__s.size() <= 2) |
| 1139 | { |
| 1140 | __r = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1141 | if (__r.size() == 1 || __r.size() == 3) |
| 1142 | __r = __s; |
| 1143 | else |
| 1144 | __r.clear(); |
| 1145 | } |
| 1146 | } |
| 1147 | return __r; |
| 1148 | } |
| 1149 | |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1150 | // lookup_classname |
| 1151 | |
| 1152 | ctype_base::mask __get_classname(const char* __s, bool __icase); |
| 1153 | |
| 1154 | template <class _CharT> |
| 1155 | template <class _ForwardIterator> |
| 1156 | typename regex_traits<_CharT>::char_class_type |
| 1157 | regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, |
| 1158 | _ForwardIterator __l, |
| 1159 | bool __icase, char) const |
| 1160 | { |
| 1161 | string_type __s(__f, __l); |
| 1162 | __ct_->tolower(&__s[0], &__s[0] + __s.size()); |
| 1163 | return __get_classname(__s.c_str(), __icase); |
| 1164 | } |
| 1165 | |
| 1166 | template <class _CharT> |
| 1167 | template <class _ForwardIterator> |
| 1168 | typename regex_traits<_CharT>::char_class_type |
| 1169 | regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, |
| 1170 | _ForwardIterator __l, |
| 1171 | bool __icase, wchar_t) const |
| 1172 | { |
| 1173 | string_type __s(__f, __l); |
| 1174 | __ct_->tolower(&__s[0], &__s[0] + __s.size()); |
| 1175 | string __n; |
| 1176 | __n.reserve(__s.size()); |
| 1177 | for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); |
| 1178 | __i != __e; ++__i) |
| 1179 | { |
| 1180 | if (static_cast<unsigned>(*__i) >= 127) |
| 1181 | return char_class_type(); |
| 1182 | __n.push_back(char(*__i)); |
| 1183 | } |
| 1184 | return __get_classname(__n.c_str(), __icase); |
| 1185 | } |
| 1186 | |
| 1187 | template <class _CharT> |
| 1188 | bool |
| 1189 | regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const |
| 1190 | { |
| 1191 | if (__ct_->is(__m, __c)) |
| 1192 | return true; |
| 1193 | return (__c == '_' && (__m & __regex_word)); |
| 1194 | } |
| 1195 | |
| 1196 | template <class _CharT> |
| 1197 | int |
| 1198 | regex_traits<_CharT>::__value(unsigned char __ch, int __radix) |
| 1199 | { |
| 1200 | if ((__ch & 0xF8u) == 0x30) // '0' <= __ch && __ch <= '7' |
| 1201 | return __ch - '0'; |
| 1202 | if (__radix != 8) |
| 1203 | { |
| 1204 | if ((__ch & 0xFEu) == 0x38) // '8' <= __ch && __ch <= '9' |
| 1205 | return __ch - '0'; |
| 1206 | if (__radix == 16) |
| 1207 | { |
| 1208 | __ch |= 0x20; // tolower |
| 1209 | if ('a' <= __ch && __ch <= 'f') |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 1210 | return __ch - ('a' - 10); |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1211 | } |
| 1212 | } |
| 1213 | return -1; |
| 1214 | } |
| 1215 | |
| 1216 | template <class _CharT> |
| 1217 | inline |
| 1218 | int |
| 1219 | regex_traits<_CharT>::__value(wchar_t __ch, int __radix) const |
| 1220 | { |
| 1221 | return __value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix); |
| 1222 | } |
| 1223 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1224 | template <class _CharT> class __node; |
| 1225 | |
| 1226 | template <class _BidirectionalIterator> class sub_match; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1227 | |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1228 | template <class _BidirectionalIterator, |
| 1229 | class _Allocator = allocator<sub_match<_BidirectionalIterator> > > |
| 1230 | class match_results; |
| 1231 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1232 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1233 | struct __state |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1234 | { |
| 1235 | enum |
| 1236 | { |
| 1237 | __end_state = -1000, |
| 1238 | __consume_input, // -999 |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1239 | __begin_marked_expr, // -998 |
| 1240 | __end_marked_expr, // -997 |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1241 | __pop_state, // -996 |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1242 | __accept_and_consume, // -995 |
| 1243 | __accept_but_not_consume, // -994 |
| 1244 | __reject, // -993 |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1245 | __split, |
| 1246 | __repeat |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1247 | }; |
| 1248 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1249 | int __do_; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1250 | const _CharT* __first_; |
| 1251 | const _CharT* __current_; |
| 1252 | const _CharT* __last_; |
| 1253 | vector<sub_match<const _CharT*> > __sub_matches_; |
| 1254 | vector<pair<size_t, const _CharT*> > __loop_data_; |
| 1255 | const __node<_CharT>* __node_; |
| 1256 | regex_constants::match_flag_type __flags_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1257 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1258 | __state() |
| 1259 | : __do_(0), __first_(nullptr), __current_(nullptr), __last_(nullptr), |
| 1260 | __node_(nullptr), __flags_() {} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1261 | }; |
| 1262 | |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1263 | template <class _CharT> |
| 1264 | ostream& |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1265 | operator<<(ostream& os, const __state<_CharT>& c) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1266 | { |
| 1267 | os << c.__do_; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1268 | if (c.__node_) |
| 1269 | os << ", " << c.__node_->speak(); |
| 1270 | else |
| 1271 | os << ", null"; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1272 | return os; |
| 1273 | } |
| 1274 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1275 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1276 | // __node |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1277 | |
| 1278 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1279 | class __node |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1280 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1281 | __node(const __node&); |
| 1282 | __node& operator=(const __node&); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1283 | public: |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1284 | typedef _STD::__state<_CharT> __state; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1285 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1286 | __node() {} |
| 1287 | virtual ~__node() {} |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1288 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1289 | virtual void __exec(__state&) const {}; |
| 1290 | virtual void __exec_split(bool, __state&) const {}; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1291 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1292 | virtual string speak() const {return "__node";} |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1293 | }; |
| 1294 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1295 | // __end_state |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1296 | |
| 1297 | template <class _CharT> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1298 | class __end_state |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1299 | : public __node<_CharT> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1300 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1301 | public: |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1302 | typedef _STD::__state<_CharT> __state; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1303 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1304 | __end_state() {} |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1305 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1306 | virtual void __exec(__state&) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1307 | |
| 1308 | virtual string speak() const {return "end state";} |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1309 | }; |
| 1310 | |
| 1311 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1312 | void |
| 1313 | __end_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1314 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1315 | __s.__do_ = __state::__end_state; |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1316 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1317 | |
| 1318 | // __has_one_state |
| 1319 | |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1320 | template <class _CharT> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1321 | class __has_one_state |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1322 | : public __node<_CharT> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1323 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1324 | __node<_CharT>* __first_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1325 | |
| 1326 | public: |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1327 | explicit __has_one_state(__node<_CharT>* __s) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1328 | : __first_(__s) {} |
| 1329 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1330 | __node<_CharT>* first() const {return __first_;} |
| 1331 | __node<_CharT>*& first() {return __first_;} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1332 | }; |
| 1333 | |
| 1334 | // __owns_one_state |
| 1335 | |
| 1336 | template <class _CharT> |
| 1337 | class __owns_one_state |
| 1338 | : public __has_one_state<_CharT> |
| 1339 | { |
| 1340 | typedef __has_one_state<_CharT> base; |
| 1341 | |
| 1342 | public: |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1343 | explicit __owns_one_state(__node<_CharT>* __s) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1344 | : base(__s) {} |
| 1345 | |
| 1346 | virtual ~__owns_one_state(); |
| 1347 | }; |
| 1348 | |
| 1349 | template <class _CharT> |
| 1350 | __owns_one_state<_CharT>::~__owns_one_state() |
| 1351 | { |
| 1352 | delete this->first(); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1353 | } |
| 1354 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1355 | // __empty_state |
| 1356 | |
| 1357 | template <class _CharT> |
| 1358 | class __empty_state |
| 1359 | : public __owns_one_state<_CharT> |
| 1360 | { |
| 1361 | typedef __owns_one_state<_CharT> base; |
| 1362 | |
| 1363 | public: |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1364 | typedef _STD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1365 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1366 | explicit __empty_state(__node<_CharT>* __s) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1367 | : base(__s) {} |
| 1368 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1369 | virtual void __exec(__state&) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1370 | |
| 1371 | virtual string speak() const {return "empty state";} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1372 | }; |
| 1373 | |
| 1374 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1375 | void |
| 1376 | __empty_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1377 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1378 | __s.__do_ = __state::__accept_but_not_consume; |
| 1379 | __s.__node_ = this->first(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1380 | } |
| 1381 | |
| 1382 | // __empty_non_own_state |
| 1383 | |
| 1384 | template <class _CharT> |
| 1385 | class __empty_non_own_state |
| 1386 | : public __has_one_state<_CharT> |
| 1387 | { |
| 1388 | typedef __has_one_state<_CharT> base; |
| 1389 | |
| 1390 | public: |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1391 | typedef _STD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1392 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1393 | explicit __empty_non_own_state(__node<_CharT>* __s) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1394 | : base(__s) {} |
| 1395 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1396 | virtual void __exec(__state&) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1397 | |
| 1398 | virtual string speak() const {return "empty non-owning state";} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1399 | }; |
| 1400 | |
| 1401 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1402 | void |
| 1403 | __empty_non_own_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1404 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1405 | __s.__do_ = __state::__accept_but_not_consume; |
| 1406 | __s.__node_ = this->first(); |
| 1407 | } |
| 1408 | |
| 1409 | // __repeat_one_loop |
| 1410 | |
| 1411 | template <class _CharT> |
| 1412 | class __repeat_one_loop |
| 1413 | : public __has_one_state<_CharT> |
| 1414 | { |
| 1415 | typedef __has_one_state<_CharT> base; |
| 1416 | |
| 1417 | public: |
| 1418 | typedef _STD::__state<_CharT> __state; |
| 1419 | |
| 1420 | explicit __repeat_one_loop(__node<_CharT>* __s) |
| 1421 | : base(__s) {} |
| 1422 | |
| 1423 | virtual void __exec(__state&) const; |
| 1424 | |
| 1425 | virtual string speak() const {return "repeat loop";} |
| 1426 | }; |
| 1427 | |
| 1428 | template <class _CharT> |
| 1429 | void |
| 1430 | __repeat_one_loop<_CharT>::__exec(__state& __s) const |
| 1431 | { |
| 1432 | __s.__do_ = __state::__repeat; |
| 1433 | __s.__node_ = this->first(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1434 | } |
| 1435 | |
| 1436 | // __owns_two_states |
| 1437 | |
| 1438 | template <class _CharT> |
| 1439 | class __owns_two_states |
| 1440 | : public __owns_one_state<_CharT> |
| 1441 | { |
| 1442 | typedef __owns_one_state<_CharT> base; |
| 1443 | |
| 1444 | base* __second_; |
| 1445 | |
| 1446 | public: |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1447 | explicit __owns_two_states(__node<_CharT>* __s1, base* __s2) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1448 | : base(__s1), __second_(__s2) {} |
| 1449 | |
| 1450 | virtual ~__owns_two_states(); |
| 1451 | |
| 1452 | base* second() const {return __second_;} |
| 1453 | base*& second() {return __second_;} |
| 1454 | }; |
| 1455 | |
| 1456 | template <class _CharT> |
| 1457 | __owns_two_states<_CharT>::~__owns_two_states() |
| 1458 | { |
| 1459 | delete __second_; |
| 1460 | } |
| 1461 | |
| 1462 | // __loop |
| 1463 | |
| 1464 | template <class _CharT> |
| 1465 | class __loop |
| 1466 | : public __owns_two_states<_CharT> |
| 1467 | { |
| 1468 | typedef __owns_two_states<_CharT> base; |
| 1469 | |
| 1470 | size_t __min_; |
| 1471 | size_t __max_; |
| 1472 | unsigned __loop_id_; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1473 | unsigned __mexp_begin_; |
| 1474 | unsigned __mexp_end_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1475 | bool __greedy_; |
| 1476 | |
| 1477 | public: |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1478 | typedef _STD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1479 | |
| 1480 | explicit __loop(unsigned __loop_id, |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1481 | __node<_CharT>* __s1, __owns_one_state<_CharT>* __s2, |
| 1482 | unsigned __mexp_begin, unsigned __mexp_end, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1483 | bool __greedy = true, |
| 1484 | size_t __min = 0, |
| 1485 | size_t __max = numeric_limits<size_t>::max()) |
| 1486 | : base(__s1, __s2), __min_(__min), __max_(__max), __loop_id_(__loop_id), |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1487 | __mexp_begin_(__mexp_begin), __mexp_end_(__mexp_end), |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1488 | __greedy_(__greedy) {} |
| 1489 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1490 | virtual void __exec(__state& __s) const; |
| 1491 | virtual void __exec_split(bool __second, __state& __s) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1492 | |
| 1493 | virtual string speak() const |
| 1494 | { |
| 1495 | ostringstream os; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1496 | os << "loop "<< __loop_id_ << " {" << __min_ << ',' << __max_ << "}"; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1497 | if (!__greedy_) |
| 1498 | os << " not"; |
| 1499 | os << " greedy"; |
| 1500 | return os.str(); |
| 1501 | } |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1502 | |
| 1503 | private: |
| 1504 | void __init_repeat(__state& __s) const |
| 1505 | { |
| 1506 | __s.__loop_data_[__loop_id_].second = __s.__current_; |
| 1507 | for (size_t __i = __mexp_begin_-1; __i != __mexp_end_-1; ++__i) |
| 1508 | { |
| 1509 | __s.__sub_matches_[__i].first = __s.__last_; |
| 1510 | __s.__sub_matches_[__i].second = __s.__last_; |
| 1511 | __s.__sub_matches_[__i].matched = false; |
| 1512 | } |
| 1513 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1514 | }; |
| 1515 | |
| 1516 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1517 | void |
| 1518 | __loop<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1519 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1520 | if (__s.__do_ == __state::__repeat) |
| 1521 | { |
| 1522 | bool __do_repeat = ++__s.__loop_data_[__loop_id_].first < __max_; |
| 1523 | bool __do_alt = __s.__loop_data_[__loop_id_].first >= __min_; |
| 1524 | if (__do_repeat && __do_alt && |
| 1525 | __s.__loop_data_[__loop_id_].second == __s.__current_) |
| 1526 | __do_repeat = false; |
| 1527 | if (__do_repeat && __do_alt) |
| 1528 | __s.__do_ = __state::__split; |
| 1529 | else if (__do_repeat) |
| 1530 | { |
| 1531 | __s.__do_ = __state::__accept_but_not_consume; |
| 1532 | __s.__node_ = this->first(); |
| 1533 | __init_repeat(__s); |
| 1534 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1535 | else |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1536 | { |
| 1537 | __s.__do_ = __state::__accept_but_not_consume; |
| 1538 | __s.__node_ = this->second(); |
| 1539 | } |
| 1540 | } |
| 1541 | else |
| 1542 | { |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame^] | 1543 | __s.__loop_data_[__loop_id_].first = 0; |
| 1544 | bool __do_repeat = 0 < __max_; |
| 1545 | bool __do_alt = 0 >= __min_; |
| 1546 | if (__do_repeat && __do_alt) |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1547 | __s.__do_ = __state::__split; |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame^] | 1548 | else if (__do_repeat) |
| 1549 | { |
| 1550 | __s.__do_ = __state::__accept_but_not_consume; |
| 1551 | __s.__node_ = this->first(); |
| 1552 | __init_repeat(__s); |
| 1553 | } |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1554 | else |
| 1555 | { |
| 1556 | __s.__do_ = __state::__accept_but_not_consume; |
| 1557 | __s.__node_ = this->second(); |
| 1558 | } |
| 1559 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1560 | } |
| 1561 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1562 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1563 | void |
| 1564 | __loop<_CharT>::__exec_split(bool __second, __state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1565 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1566 | __s.__do_ = __state::__accept_but_not_consume; |
| 1567 | if (__greedy_ != __second) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1568 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1569 | __s.__node_ = this->first(); |
| 1570 | __init_repeat(__s); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1571 | } |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1572 | else |
| 1573 | __s.__node_ = this->second(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1574 | } |
| 1575 | |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1576 | // __alternate |
| 1577 | |
| 1578 | template <class _CharT> |
| 1579 | class __alternate |
| 1580 | : public __owns_two_states<_CharT> |
| 1581 | { |
| 1582 | typedef __owns_two_states<_CharT> base; |
| 1583 | |
| 1584 | public: |
| 1585 | typedef _STD::__state<_CharT> __state; |
| 1586 | |
| 1587 | explicit __alternate(__owns_one_state<_CharT>* __s1, |
| 1588 | __owns_one_state<_CharT>* __s2) |
| 1589 | : base(__s1, __s2) {} |
| 1590 | |
| 1591 | virtual void __exec(__state& __s) const; |
| 1592 | virtual void __exec_split(bool __second, __state& __s) const; |
| 1593 | |
| 1594 | virtual string speak() const |
| 1595 | { |
| 1596 | ostringstream os; |
| 1597 | os << "__alternate"; |
| 1598 | return os.str(); |
| 1599 | } |
| 1600 | }; |
| 1601 | |
| 1602 | template <class _CharT> |
| 1603 | void |
| 1604 | __alternate<_CharT>::__exec(__state& __s) const |
| 1605 | { |
| 1606 | __s.__do_ = __state::__split; |
| 1607 | } |
| 1608 | |
| 1609 | template <class _CharT> |
| 1610 | void |
| 1611 | __alternate<_CharT>::__exec_split(bool __second, __state& __s) const |
| 1612 | { |
| 1613 | __s.__do_ = __state::__accept_but_not_consume; |
Howard Hinnant | 1371b2e | 2010-07-22 14:12:20 +0000 | [diff] [blame] | 1614 | if (__second) |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1615 | __s.__node_ = this->second(); |
Howard Hinnant | 1371b2e | 2010-07-22 14:12:20 +0000 | [diff] [blame] | 1616 | else |
| 1617 | __s.__node_ = this->first(); |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1618 | } |
| 1619 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1620 | // __begin_marked_subexpression |
| 1621 | |
| 1622 | template <class _CharT> |
| 1623 | class __begin_marked_subexpression |
| 1624 | : public __owns_one_state<_CharT> |
| 1625 | { |
| 1626 | typedef __owns_one_state<_CharT> base; |
| 1627 | |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1628 | unsigned __mexp_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1629 | public: |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1630 | typedef _STD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1631 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1632 | explicit __begin_marked_subexpression(unsigned __mexp, __node<_CharT>* __s) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1633 | : base(__s), __mexp_(__mexp) {} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1634 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1635 | virtual void __exec(__state&) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1636 | |
| 1637 | virtual string speak() const |
| 1638 | { |
| 1639 | ostringstream os; |
| 1640 | os << "begin marked expr " << __mexp_; |
| 1641 | return os.str(); |
| 1642 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1643 | }; |
| 1644 | |
| 1645 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1646 | void |
| 1647 | __begin_marked_subexpression<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1648 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1649 | __s.__do_ = __state::__accept_but_not_consume; |
| 1650 | __s.__sub_matches_[__mexp_-1].first = __s.__current_; |
| 1651 | __s.__node_ = this->first(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1652 | } |
| 1653 | |
| 1654 | // __end_marked_subexpression |
| 1655 | |
| 1656 | template <class _CharT> |
| 1657 | class __end_marked_subexpression |
| 1658 | : public __owns_one_state<_CharT> |
| 1659 | { |
| 1660 | typedef __owns_one_state<_CharT> base; |
| 1661 | |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1662 | unsigned __mexp_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1663 | public: |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1664 | typedef _STD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1665 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1666 | explicit __end_marked_subexpression(unsigned __mexp, __node<_CharT>* __s) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1667 | : base(__s), __mexp_(__mexp) {} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1668 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1669 | virtual void __exec(__state&) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1670 | |
| 1671 | virtual string speak() const |
| 1672 | { |
| 1673 | ostringstream os; |
| 1674 | os << "end marked expr " << __mexp_; |
| 1675 | return os.str(); |
| 1676 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1677 | }; |
| 1678 | |
| 1679 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1680 | void |
| 1681 | __end_marked_subexpression<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1682 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1683 | __s.__do_ = __state::__accept_but_not_consume; |
| 1684 | __s.__sub_matches_[__mexp_-1].second = __s.__current_; |
| 1685 | __s.__sub_matches_[__mexp_-1].matched = true; |
| 1686 | __s.__node_ = this->first(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1687 | } |
| 1688 | |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1689 | // __back_ref |
| 1690 | |
| 1691 | template <class _CharT> |
| 1692 | class __back_ref |
| 1693 | : public __owns_one_state<_CharT> |
| 1694 | { |
| 1695 | typedef __owns_one_state<_CharT> base; |
| 1696 | |
| 1697 | unsigned __mexp_; |
| 1698 | public: |
| 1699 | typedef _STD::__state<_CharT> __state; |
| 1700 | |
| 1701 | explicit __back_ref(unsigned __mexp, __node<_CharT>* __s) |
| 1702 | : base(__s), __mexp_(__mexp) {} |
| 1703 | |
| 1704 | virtual void __exec(__state&) const; |
| 1705 | |
| 1706 | virtual string speak() const |
| 1707 | { |
| 1708 | ostringstream os; |
| 1709 | os << "__back_ref " << __mexp_; |
| 1710 | return os.str(); |
| 1711 | } |
| 1712 | }; |
| 1713 | |
| 1714 | template <class _CharT> |
| 1715 | void |
| 1716 | __back_ref<_CharT>::__exec(__state& __s) const |
| 1717 | { |
| 1718 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1719 | if (__sm.matched) |
| 1720 | { |
| 1721 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1722 | if (__s.__last_ - __s.__current_ >= __len && |
| 1723 | _STD::equal(__sm.first, __sm.second, __s.__current_)) |
| 1724 | { |
| 1725 | __s.__do_ = __state::__accept_but_not_consume; |
| 1726 | __s.__current_ += __len; |
| 1727 | __s.__node_ = this->first(); |
| 1728 | } |
| 1729 | else |
| 1730 | { |
| 1731 | __s.__do_ = __state::__reject; |
| 1732 | __s.__node_ = nullptr; |
| 1733 | } |
| 1734 | } |
| 1735 | else |
| 1736 | { |
| 1737 | __s.__do_ = __state::__reject; |
| 1738 | __s.__node_ = nullptr; |
| 1739 | } |
| 1740 | } |
| 1741 | |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1742 | // __back_ref_icase |
| 1743 | |
| 1744 | template <class _CharT, class _Traits> |
| 1745 | class __back_ref_icase |
| 1746 | : public __owns_one_state<_CharT> |
| 1747 | { |
| 1748 | typedef __owns_one_state<_CharT> base; |
| 1749 | |
| 1750 | _Traits __traits_; |
| 1751 | unsigned __mexp_; |
| 1752 | public: |
| 1753 | typedef _STD::__state<_CharT> __state; |
| 1754 | |
| 1755 | explicit __back_ref_icase(const _Traits& __traits, unsigned __mexp, |
| 1756 | __node<_CharT>* __s) |
| 1757 | : base(__s), __traits_(__traits), __mexp_(__mexp) {} |
| 1758 | |
| 1759 | virtual void __exec(__state&) const; |
| 1760 | |
| 1761 | virtual string speak() const |
| 1762 | { |
| 1763 | ostringstream os; |
| 1764 | os << "__back_ref_icase " << __mexp_; |
| 1765 | return os.str(); |
| 1766 | } |
| 1767 | }; |
| 1768 | |
| 1769 | template <class _CharT, class _Traits> |
| 1770 | void |
| 1771 | __back_ref_icase<_CharT, _Traits>::__exec(__state& __s) const |
| 1772 | { |
| 1773 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1774 | if (__sm.matched) |
| 1775 | { |
| 1776 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1777 | if (__s.__last_ - __s.__current_ >= __len) |
| 1778 | { |
| 1779 | for (ptrdiff_t __i = 0; __i < __len; ++__i) |
| 1780 | { |
| 1781 | if (__traits_.translate_nocase(__sm.first[__i]) != |
| 1782 | __traits_.translate_nocase(__s.__current_[__i])) |
| 1783 | goto __not_equal; |
| 1784 | } |
| 1785 | __s.__do_ = __state::__accept_but_not_consume; |
| 1786 | __s.__current_ += __len; |
| 1787 | __s.__node_ = this->first(); |
| 1788 | } |
| 1789 | else |
| 1790 | { |
| 1791 | __s.__do_ = __state::__reject; |
| 1792 | __s.__node_ = nullptr; |
| 1793 | } |
| 1794 | } |
| 1795 | else |
| 1796 | { |
| 1797 | __not_equal: |
| 1798 | __s.__do_ = __state::__reject; |
| 1799 | __s.__node_ = nullptr; |
| 1800 | } |
| 1801 | } |
| 1802 | |
| 1803 | // __back_ref_collate |
| 1804 | |
| 1805 | template <class _CharT, class _Traits> |
| 1806 | class __back_ref_collate |
| 1807 | : public __owns_one_state<_CharT> |
| 1808 | { |
| 1809 | typedef __owns_one_state<_CharT> base; |
| 1810 | |
| 1811 | _Traits __traits_; |
| 1812 | unsigned __mexp_; |
| 1813 | public: |
| 1814 | typedef _STD::__state<_CharT> __state; |
| 1815 | |
| 1816 | explicit __back_ref_collate(const _Traits& __traits, unsigned __mexp, |
| 1817 | __node<_CharT>* __s) |
| 1818 | : base(__s), __traits_(__traits), __mexp_(__mexp) {} |
| 1819 | |
| 1820 | virtual void __exec(__state&) const; |
| 1821 | |
| 1822 | virtual string speak() const |
| 1823 | { |
| 1824 | ostringstream os; |
| 1825 | os << "__back_ref_collate " << __mexp_; |
| 1826 | return os.str(); |
| 1827 | } |
| 1828 | }; |
| 1829 | |
| 1830 | template <class _CharT, class _Traits> |
| 1831 | void |
| 1832 | __back_ref_collate<_CharT, _Traits>::__exec(__state& __s) const |
| 1833 | { |
| 1834 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1835 | if (__sm.matched) |
| 1836 | { |
| 1837 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1838 | if (__s.__last_ - __s.__current_ >= __len) |
| 1839 | { |
| 1840 | for (ptrdiff_t __i = 0; __i < __len; ++__i) |
| 1841 | { |
| 1842 | if (__traits_.translate(__sm.first[__i]) != |
| 1843 | __traits_.translate(__s.__current_[__i])) |
| 1844 | goto __not_equal; |
| 1845 | } |
| 1846 | __s.__do_ = __state::__accept_but_not_consume; |
| 1847 | __s.__current_ += __len; |
| 1848 | __s.__node_ = this->first(); |
| 1849 | } |
| 1850 | else |
| 1851 | { |
| 1852 | __s.__do_ = __state::__reject; |
| 1853 | __s.__node_ = nullptr; |
| 1854 | } |
| 1855 | } |
| 1856 | else |
| 1857 | { |
| 1858 | __not_equal: |
| 1859 | __s.__do_ = __state::__reject; |
| 1860 | __s.__node_ = nullptr; |
| 1861 | } |
| 1862 | } |
| 1863 | |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1864 | // __word_boundary |
| 1865 | |
| 1866 | template <class _CharT, class _Traits> |
| 1867 | class __word_boundary |
| 1868 | : public __owns_one_state<_CharT> |
| 1869 | { |
| 1870 | typedef __owns_one_state<_CharT> base; |
| 1871 | |
| 1872 | _Traits __traits_; |
| 1873 | bool __invert_; |
| 1874 | public: |
| 1875 | typedef _STD::__state<_CharT> __state; |
| 1876 | |
| 1877 | explicit __word_boundary(const _Traits& __traits, bool __invert, |
| 1878 | __node<_CharT>* __s) |
| 1879 | : base(__s), __traits_(__traits), __invert_(__invert) {} |
| 1880 | |
| 1881 | virtual void __exec(__state&) const; |
| 1882 | |
| 1883 | virtual string speak() const |
| 1884 | { |
| 1885 | ostringstream os; |
| 1886 | if (__invert_) |
| 1887 | os << "__word_boundary"; |
| 1888 | else |
| 1889 | os << "not __word_boundary"; |
| 1890 | return os.str(); |
| 1891 | } |
| 1892 | }; |
| 1893 | |
| 1894 | template <class _CharT, class _Traits> |
| 1895 | void |
| 1896 | __word_boundary<_CharT, _Traits>::__exec(__state& __s) const |
| 1897 | { |
| 1898 | bool __is_word_b = false; |
| 1899 | if (__s.__first_ != __s.__last_) |
| 1900 | { |
| 1901 | if (__s.__current_ == __s.__last_) |
| 1902 | { |
| 1903 | if (!(__s.__flags_ & regex_constants::match_not_eow)) |
| 1904 | { |
| 1905 | _CharT __c = __s.__current_[-1]; |
| 1906 | __is_word_b = __c == '_' || |
| 1907 | __traits_.isctype(__c, ctype_base::alnum); |
| 1908 | } |
| 1909 | } |
| 1910 | else if (__s.__current_ == __s.__first_) |
| 1911 | { |
| 1912 | if (!(__s.__flags_ & regex_constants::match_not_bow)) |
| 1913 | { |
| 1914 | _CharT __c = *__s.__current_; |
| 1915 | __is_word_b = __c == '_' || |
| 1916 | __traits_.isctype(__c, ctype_base::alnum); |
| 1917 | } |
| 1918 | } |
| 1919 | else |
| 1920 | { |
| 1921 | _CharT __c1 = __s.__current_[-1]; |
| 1922 | _CharT __c2 = *__s.__current_; |
| 1923 | bool __is_c1_b = __c1 == '_' || |
| 1924 | __traits_.isctype(__c1, ctype_base::alnum); |
| 1925 | bool __is_c2_b = __c2 == '_' || |
| 1926 | __traits_.isctype(__c2, ctype_base::alnum); |
| 1927 | __is_word_b = __is_c1_b != __is_c2_b; |
| 1928 | } |
| 1929 | } |
| 1930 | if (__is_word_b != __invert_) |
| 1931 | { |
| 1932 | __s.__do_ = __state::__accept_but_not_consume; |
| 1933 | __s.__node_ = this->first(); |
| 1934 | } |
| 1935 | else |
| 1936 | { |
| 1937 | __s.__do_ = __state::__reject; |
| 1938 | __s.__node_ = nullptr; |
| 1939 | } |
| 1940 | } |
| 1941 | |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 1942 | // __r_anchor |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1943 | |
| 1944 | template <class _CharT> |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 1945 | class __r_anchor |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1946 | : public __owns_one_state<_CharT> |
| 1947 | { |
| 1948 | typedef __owns_one_state<_CharT> base; |
| 1949 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1950 | public: |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1951 | typedef _STD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1952 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1953 | __r_anchor(__node<_CharT>* __s) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 1954 | : base(__s) {} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1955 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1956 | virtual void __exec(__state&) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1957 | |
| 1958 | virtual string speak() const |
| 1959 | { |
| 1960 | ostringstream os; |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 1961 | os << "right anchor"; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1962 | return os.str(); |
| 1963 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1964 | }; |
| 1965 | |
| 1966 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1967 | void |
| 1968 | __r_anchor<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1969 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1970 | if (__s.__current_ == __s.__last_) |
| 1971 | { |
| 1972 | __s.__do_ = __state::__accept_but_not_consume; |
| 1973 | __s.__node_ = this->first(); |
| 1974 | } |
| 1975 | else |
| 1976 | { |
| 1977 | __s.__do_ = __state::__reject; |
| 1978 | __s.__node_ = nullptr; |
| 1979 | } |
| 1980 | } |
| 1981 | |
| 1982 | // __match_any |
| 1983 | |
| 1984 | template <class _CharT> |
| 1985 | class __match_any |
| 1986 | : public __owns_one_state<_CharT> |
| 1987 | { |
| 1988 | typedef __owns_one_state<_CharT> base; |
| 1989 | |
| 1990 | public: |
| 1991 | typedef _STD::__state<_CharT> __state; |
| 1992 | |
| 1993 | __match_any(__node<_CharT>* __s) |
| 1994 | : base(__s) {} |
| 1995 | |
| 1996 | virtual void __exec(__state&) const; |
| 1997 | |
| 1998 | virtual string speak() const |
| 1999 | { |
| 2000 | ostringstream os; |
| 2001 | os << "match any"; |
| 2002 | return os.str(); |
| 2003 | } |
| 2004 | }; |
| 2005 | |
| 2006 | template <class _CharT> |
| 2007 | void |
| 2008 | __match_any<_CharT>::__exec(__state& __s) const |
| 2009 | { |
| 2010 | if (__s.__current_ != __s.__last_ && *__s.__current_ != 0) |
| 2011 | { |
| 2012 | __s.__do_ = __state::__accept_and_consume; |
| 2013 | ++__s.__current_; |
| 2014 | __s.__node_ = this->first(); |
| 2015 | } |
| 2016 | else |
| 2017 | { |
| 2018 | __s.__do_ = __state::__reject; |
| 2019 | __s.__node_ = nullptr; |
| 2020 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2021 | } |
| 2022 | |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2023 | // __match_any_but_newline |
| 2024 | |
| 2025 | template <class _CharT> |
| 2026 | class __match_any_but_newline |
| 2027 | : public __owns_one_state<_CharT> |
| 2028 | { |
| 2029 | typedef __owns_one_state<_CharT> base; |
| 2030 | |
| 2031 | public: |
| 2032 | typedef _STD::__state<_CharT> __state; |
| 2033 | |
| 2034 | __match_any_but_newline(__node<_CharT>* __s) |
| 2035 | : base(__s) {} |
| 2036 | |
| 2037 | virtual void __exec(__state&) const; |
| 2038 | |
| 2039 | virtual string speak() const |
| 2040 | { |
| 2041 | ostringstream os; |
| 2042 | os << "match any but newline"; |
| 2043 | return os.str(); |
| 2044 | } |
| 2045 | }; |
| 2046 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2047 | // __match_char |
| 2048 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2049 | template <class _CharT> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2050 | class __match_char |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2051 | : public __owns_one_state<_CharT> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2052 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2053 | typedef __owns_one_state<_CharT> base; |
| 2054 | |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2055 | _CharT __c_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2056 | |
| 2057 | __match_char(const __match_char&); |
| 2058 | __match_char& operator=(const __match_char&); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2059 | public: |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2060 | typedef _STD::__state<_CharT> __state; |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2061 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2062 | __match_char(_CharT __c, __node<_CharT>* __s) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2063 | : base(__s), __c_(__c) {} |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2064 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2065 | virtual void __exec(__state&) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2066 | |
| 2067 | virtual string speak() const |
| 2068 | { |
| 2069 | ostringstream os; |
| 2070 | os << "match char " << __c_; |
| 2071 | return os.str(); |
| 2072 | } |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2073 | }; |
| 2074 | |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2075 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2076 | void |
| 2077 | __match_char<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2078 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2079 | if (__s.__current_ != __s.__last_ && *__s.__current_ == __c_) |
| 2080 | { |
| 2081 | __s.__do_ = __state::__accept_and_consume; |
| 2082 | ++__s.__current_; |
| 2083 | __s.__node_ = this->first(); |
| 2084 | } |
| 2085 | else |
| 2086 | { |
| 2087 | __s.__do_ = __state::__reject; |
| 2088 | __s.__node_ = nullptr; |
| 2089 | } |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2090 | } |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2091 | |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2092 | // __match_char_icase |
| 2093 | |
| 2094 | template <class _CharT, class _Traits> |
| 2095 | class __match_char_icase |
| 2096 | : public __owns_one_state<_CharT> |
| 2097 | { |
| 2098 | typedef __owns_one_state<_CharT> base; |
| 2099 | |
| 2100 | _Traits __traits_; |
| 2101 | _CharT __c_; |
| 2102 | |
| 2103 | __match_char_icase(const __match_char_icase&); |
| 2104 | __match_char_icase& operator=(const __match_char_icase&); |
| 2105 | public: |
| 2106 | typedef _STD::__state<_CharT> __state; |
| 2107 | |
| 2108 | __match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s) |
| 2109 | : base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {} |
| 2110 | |
| 2111 | virtual void __exec(__state&) const; |
| 2112 | |
| 2113 | virtual string speak() const |
| 2114 | { |
| 2115 | ostringstream os; |
| 2116 | os << "match char icase " << __c_; |
| 2117 | return os.str(); |
| 2118 | } |
| 2119 | }; |
| 2120 | |
| 2121 | template <class _CharT, class _Traits> |
| 2122 | void |
| 2123 | __match_char_icase<_CharT, _Traits>::__exec(__state& __s) const |
| 2124 | { |
| 2125 | if (__s.__current_ != __s.__last_ && |
| 2126 | __traits_.translate_nocase(*__s.__current_) == __c_) |
| 2127 | { |
| 2128 | __s.__do_ = __state::__accept_and_consume; |
| 2129 | ++__s.__current_; |
| 2130 | __s.__node_ = this->first(); |
| 2131 | } |
| 2132 | else |
| 2133 | { |
| 2134 | __s.__do_ = __state::__reject; |
| 2135 | __s.__node_ = nullptr; |
| 2136 | } |
| 2137 | } |
| 2138 | |
| 2139 | // __match_char_collate |
| 2140 | |
| 2141 | template <class _CharT, class _Traits> |
| 2142 | class __match_char_collate |
| 2143 | : public __owns_one_state<_CharT> |
| 2144 | { |
| 2145 | typedef __owns_one_state<_CharT> base; |
| 2146 | |
| 2147 | _Traits __traits_; |
| 2148 | _CharT __c_; |
| 2149 | |
| 2150 | __match_char_collate(const __match_char_collate&); |
| 2151 | __match_char_collate& operator=(const __match_char_collate&); |
| 2152 | public: |
| 2153 | typedef _STD::__state<_CharT> __state; |
| 2154 | |
| 2155 | __match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s) |
| 2156 | : base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {} |
| 2157 | |
| 2158 | virtual void __exec(__state&) const; |
| 2159 | |
| 2160 | virtual string speak() const |
| 2161 | { |
| 2162 | ostringstream os; |
| 2163 | os << "match char icase " << __c_; |
| 2164 | return os.str(); |
| 2165 | } |
| 2166 | }; |
| 2167 | |
| 2168 | template <class _CharT, class _Traits> |
| 2169 | void |
| 2170 | __match_char_collate<_CharT, _Traits>::__exec(__state& __s) const |
| 2171 | { |
| 2172 | if (__s.__current_ != __s.__last_ && |
| 2173 | __traits_.translate(*__s.__current_) == __c_) |
| 2174 | { |
| 2175 | __s.__do_ = __state::__accept_and_consume; |
| 2176 | ++__s.__current_; |
| 2177 | __s.__node_ = this->first(); |
| 2178 | } |
| 2179 | else |
| 2180 | { |
| 2181 | __s.__do_ = __state::__reject; |
| 2182 | __s.__node_ = nullptr; |
| 2183 | } |
| 2184 | } |
| 2185 | |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2186 | // __bracket_expression |
| 2187 | |
| 2188 | template <class _CharT, class _Traits> |
| 2189 | class __bracket_expression |
| 2190 | : public __owns_one_state<_CharT> |
| 2191 | { |
| 2192 | typedef __owns_one_state<_CharT> base; |
| 2193 | typedef typename _Traits::string_type string_type; |
| 2194 | |
| 2195 | _Traits __traits_; |
| 2196 | vector<_CharT> __chars_; |
| 2197 | vector<pair<string_type, string_type> > __ranges_; |
| 2198 | vector<pair<_CharT, _CharT> > __digraphs_; |
| 2199 | vector<string_type> __equivalences_; |
| 2200 | ctype_base::mask __mask_; |
| 2201 | bool __negate_; |
| 2202 | bool __icase_; |
| 2203 | bool __collate_; |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2204 | bool __might_have_digraph_; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2205 | |
| 2206 | __bracket_expression(const __bracket_expression&); |
| 2207 | __bracket_expression& operator=(const __bracket_expression&); |
| 2208 | public: |
| 2209 | typedef _STD::__state<_CharT> __state; |
| 2210 | |
| 2211 | __bracket_expression(const _Traits& __traits, __node<_CharT>* __s, |
| 2212 | bool __negate, bool __icase, bool __collate) |
| 2213 | : base(__s), __traits_(__traits), __mask_(), __negate_(__negate), |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2214 | __icase_(__icase), __collate_(__collate), |
| 2215 | __might_have_digraph_(__traits_.getloc().name() != "C") {} |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2216 | |
| 2217 | virtual void __exec(__state&) const; |
| 2218 | |
| 2219 | void __add_char(_CharT __c) |
| 2220 | { |
| 2221 | if (__icase_) |
| 2222 | __chars_.push_back(__traits_.translate_nocase(__c)); |
| 2223 | else if (__collate_) |
| 2224 | __chars_.push_back(__traits_.translate(__c)); |
| 2225 | else |
| 2226 | __chars_.push_back(__c); |
| 2227 | } |
| 2228 | void __add_range(string_type __b, string_type __e) |
| 2229 | { |
| 2230 | if (__collate_) |
| 2231 | { |
| 2232 | if (__icase_) |
| 2233 | { |
| 2234 | for (size_t __i = 0; __i < __b.size(); ++__i) |
| 2235 | __b[__i] = __traits_.translate_nocase(__b[__i]); |
| 2236 | for (size_t __i = 0; __i < __e.size(); ++__i) |
| 2237 | __e[__i] = __traits_.translate_nocase(__e[__i]); |
| 2238 | } |
| 2239 | else |
| 2240 | { |
| 2241 | for (size_t __i = 0; __i < __b.size(); ++__i) |
| 2242 | __b[__i] = __traits_.translate(__b[__i]); |
| 2243 | for (size_t __i = 0; __i < __e.size(); ++__i) |
| 2244 | __e[__i] = __traits_.translate(__e[__i]); |
| 2245 | } |
| 2246 | __ranges_.push_back(make_pair( |
| 2247 | __traits_.transform(__b.begin(), __b.end()), |
| 2248 | __traits_.transform(__e.begin(), __e.end()))); |
| 2249 | } |
| 2250 | else |
| 2251 | { |
| 2252 | if (__b.size() != 1 || __e.size() != 1) |
| 2253 | throw regex_error(regex_constants::error_collate); |
| 2254 | if (__icase_) |
| 2255 | { |
| 2256 | __b[0] = __traits_.translate_nocase(__b[0]); |
| 2257 | __e[0] = __traits_.translate_nocase(__e[0]); |
| 2258 | } |
| 2259 | __ranges_.push_back(make_pair(_STD::move(__b), _STD::move(__e))); |
| 2260 | } |
| 2261 | } |
| 2262 | void __add_digraph(_CharT __c1, _CharT __c2) |
| 2263 | { |
| 2264 | if (__icase_) |
| 2265 | __digraphs_.push_back(make_pair(__traits_.translate_nocase(__c1), |
| 2266 | __traits_.translate_nocase(__c2))); |
| 2267 | else if (__collate_) |
| 2268 | __digraphs_.push_back(make_pair(__traits_.translate(__c1), |
| 2269 | __traits_.translate(__c2))); |
| 2270 | else |
| 2271 | __digraphs_.push_back(make_pair(__c1, __c2)); |
| 2272 | } |
| 2273 | void __add_equivalence(const string_type& __s) |
| 2274 | {__equivalences_.push_back(__s);} |
| 2275 | void __add_class(ctype_base::mask __mask) |
| 2276 | {__mask_ |= __mask;} |
| 2277 | |
| 2278 | virtual string speak() const |
| 2279 | { |
| 2280 | ostringstream os; |
| 2281 | os << "__bracket_expression "; |
| 2282 | return os.str(); |
| 2283 | } |
| 2284 | }; |
| 2285 | |
| 2286 | template <class _CharT, class _Traits> |
| 2287 | void |
| 2288 | __bracket_expression<_CharT, _Traits>::__exec(__state& __s) const |
| 2289 | { |
| 2290 | bool __found = false; |
| 2291 | unsigned __consumed = 0; |
| 2292 | if (__s.__current_ != __s.__last_) |
| 2293 | { |
| 2294 | ++__consumed; |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2295 | if (__might_have_digraph_) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2296 | { |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2297 | const _CharT* __next = next(__s.__current_); |
| 2298 | if (__next != __s.__last_) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2299 | { |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2300 | pair<_CharT, _CharT> __ch2(*__s.__current_, *__next); |
| 2301 | if (__icase_) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2302 | { |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2303 | __ch2.first = __traits_.translate_nocase(__ch2.first); |
| 2304 | __ch2.second = __traits_.translate_nocase(__ch2.second); |
| 2305 | } |
| 2306 | else if (__collate_) |
| 2307 | { |
| 2308 | __ch2.first = __traits_.translate(__ch2.first); |
| 2309 | __ch2.second = __traits_.translate(__ch2.second); |
| 2310 | } |
| 2311 | if (!__traits_.lookup_collatename(&__ch2.first, &__ch2.first+2).empty()) |
| 2312 | { |
| 2313 | // __ch2 is a digraph in this locale |
| 2314 | ++__consumed; |
| 2315 | for (size_t __i = 0; __i < __digraphs_.size(); ++__i) |
| 2316 | { |
| 2317 | if (__ch2 == __digraphs_[__i]) |
| 2318 | { |
| 2319 | __found = true; |
| 2320 | goto __exit; |
| 2321 | } |
| 2322 | } |
| 2323 | if (__collate_ && !__ranges_.empty()) |
| 2324 | { |
| 2325 | string_type __s2 = __traits_.transform(&__ch2.first, |
| 2326 | &__ch2.first + 2); |
| 2327 | for (size_t __i = 0; __i < __ranges_.size(); ++__i) |
| 2328 | { |
| 2329 | if (__ranges_[__i].first <= __s2 && |
| 2330 | __s2 <= __ranges_[__i].second) |
| 2331 | { |
| 2332 | __found = true; |
| 2333 | goto __exit; |
| 2334 | } |
| 2335 | } |
| 2336 | } |
| 2337 | if (!__equivalences_.empty()) |
| 2338 | { |
| 2339 | string_type __s2 = __traits_.transform_primary(&__ch2.first, |
| 2340 | &__ch2.first + 2); |
| 2341 | for (size_t __i = 0; __i < __equivalences_.size(); ++__i) |
| 2342 | { |
| 2343 | if (__s2 == __equivalences_[__i]) |
| 2344 | { |
| 2345 | __found = true; |
| 2346 | goto __exit; |
| 2347 | } |
| 2348 | } |
| 2349 | } |
| 2350 | if (__traits_.isctype(__ch2.first, __mask_) && |
| 2351 | __traits_.isctype(__ch2.second, __mask_)) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2352 | { |
| 2353 | __found = true; |
| 2354 | goto __exit; |
| 2355 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2356 | goto __exit; |
| 2357 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2358 | } |
| 2359 | } |
| 2360 | // test *__s.__current_ as not a digraph |
| 2361 | _CharT __ch = *__s.__current_; |
| 2362 | if (__icase_) |
| 2363 | __ch = __traits_.translate_nocase(__ch); |
| 2364 | else if (__collate_) |
| 2365 | __ch = __traits_.translate(__ch); |
| 2366 | for (size_t __i = 0; __i < __chars_.size(); ++__i) |
| 2367 | { |
| 2368 | if (__ch == __chars_[__i]) |
| 2369 | { |
| 2370 | __found = true; |
| 2371 | goto __exit; |
| 2372 | } |
| 2373 | } |
| 2374 | if (!__ranges_.empty()) |
| 2375 | { |
| 2376 | string_type __s2 = __collate_ ? |
| 2377 | __traits_.transform(&__ch, &__ch + 1) : |
| 2378 | string_type(1, __ch); |
| 2379 | for (size_t __i = 0; __i < __ranges_.size(); ++__i) |
| 2380 | { |
| 2381 | if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second) |
| 2382 | { |
| 2383 | __found = true; |
| 2384 | goto __exit; |
| 2385 | } |
| 2386 | } |
| 2387 | } |
| 2388 | if (!__equivalences_.empty()) |
| 2389 | { |
| 2390 | string_type __s2 = __traits_.transform_primary(&__ch, &__ch + 1); |
| 2391 | for (size_t __i = 0; __i < __equivalences_.size(); ++__i) |
| 2392 | { |
| 2393 | if (__s2 == __equivalences_[__i]) |
| 2394 | { |
| 2395 | __found = true; |
| 2396 | goto __exit; |
| 2397 | } |
| 2398 | } |
| 2399 | } |
| 2400 | if (__traits_.isctype(__ch, __mask_)) |
| 2401 | __found = true; |
| 2402 | } |
| 2403 | else |
| 2404 | __found = __negate_; // force reject |
| 2405 | __exit: |
| 2406 | if (__found != __negate_) |
| 2407 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2408 | __s.__do_ = __state::__accept_and_consume; |
| 2409 | __s.__current_ += __consumed; |
| 2410 | __s.__node_ = this->first(); |
| 2411 | } |
| 2412 | else |
| 2413 | { |
| 2414 | __s.__do_ = __state::__reject; |
| 2415 | __s.__node_ = nullptr; |
| 2416 | } |
| 2417 | } |
| 2418 | |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2419 | // __lookahead |
| 2420 | |
| 2421 | template <class _CharT, class _Traits> |
| 2422 | class __lookahead |
| 2423 | : public __owns_one_state<_CharT> |
| 2424 | { |
| 2425 | typedef __owns_one_state<_CharT> base; |
| 2426 | |
| 2427 | _Traits __traits_; |
| 2428 | bool __invert_; |
| 2429 | |
| 2430 | __lookahead(const __lookahead&); |
| 2431 | __lookahead& operator=(const __lookahead&); |
| 2432 | public: |
| 2433 | typedef _STD::__state<_CharT> __state; |
| 2434 | |
| 2435 | __lookahead(const _Traits& __traits, bool __invert, __node<_CharT>* __s) |
| 2436 | : base(__s), __traits_(__traits), __invert_(__invert) {} |
| 2437 | |
| 2438 | virtual void __exec(__state&) const; |
| 2439 | |
| 2440 | virtual string speak() const |
| 2441 | { |
| 2442 | ostringstream os; |
| 2443 | if (__invert_) |
| 2444 | os << "lookahead"; |
| 2445 | else |
| 2446 | os << "not lookahead"; |
| 2447 | return os.str(); |
| 2448 | } |
| 2449 | }; |
| 2450 | |
| 2451 | template <class _CharT, class _Traits> |
| 2452 | void |
| 2453 | __lookahead<_CharT, _Traits>::__exec(__state& __s) const |
| 2454 | { |
| 2455 | // match_results<const _CharT*> __m; |
| 2456 | // __m.__init(1 + mark_count(), __s.__current_, __s.__last_); |
| 2457 | // bool __matched = __exp_.__match_at_start_ecma(__s.__current_, __s.__last_, |
| 2458 | // __m, __s.__flags_); |
| 2459 | // if (__matched != __invert_) |
| 2460 | // { |
| 2461 | // __s.__do_ = __state::__accept_but_not_consume; |
| 2462 | // __s.__node_ = this->first(); |
| 2463 | // } |
| 2464 | // else |
| 2465 | // { |
| 2466 | // __s.__do_ = __state::__reject; |
| 2467 | // __s.__node_ = nullptr; |
| 2468 | // } |
| 2469 | } |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2470 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2471 | template <class _CharT, class _Traits = regex_traits<_CharT> > |
| 2472 | class basic_regex |
| 2473 | { |
| 2474 | public: |
| 2475 | // types: |
| 2476 | typedef _CharT value_type; |
| 2477 | typedef regex_constants::syntax_option_type flag_type; |
| 2478 | typedef typename _Traits::locale_type locale_type; |
| 2479 | |
| 2480 | private: |
| 2481 | _Traits __traits_; |
| 2482 | flag_type __flags_; |
| 2483 | unsigned __marked_count_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2484 | unsigned __loop_count_; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2485 | int __open_count_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2486 | shared_ptr<__empty_state<_CharT> > __start_; |
| 2487 | __owns_one_state<_CharT>* __end_; |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2488 | bool __left_anchor_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2489 | |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2490 | typedef _STD::__state<_CharT> __state; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2491 | typedef _STD::__node<_CharT> __node; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2492 | |
| 2493 | public: |
| 2494 | // constants: |
| 2495 | static const/*expr*/ regex_constants::syntax_option_type icase = regex_constants::icase; |
| 2496 | static const/*expr*/ regex_constants::syntax_option_type nosubs = regex_constants::nosubs; |
| 2497 | static const/*expr*/ regex_constants::syntax_option_type optimize = regex_constants::optimize; |
| 2498 | static const/*expr*/ regex_constants::syntax_option_type collate = regex_constants::collate; |
| 2499 | static const/*expr*/ regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript; |
| 2500 | static const/*expr*/ regex_constants::syntax_option_type basic = regex_constants::basic; |
| 2501 | static const/*expr*/ regex_constants::syntax_option_type extended = regex_constants::extended; |
| 2502 | static const/*expr*/ regex_constants::syntax_option_type awk = regex_constants::awk; |
| 2503 | static const/*expr*/ regex_constants::syntax_option_type grep = regex_constants::grep; |
| 2504 | static const/*expr*/ regex_constants::syntax_option_type egrep = regex_constants::egrep; |
| 2505 | |
| 2506 | // construct/copy/destroy: |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2507 | basic_regex() |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2508 | : __flags_(), __marked_count_(0), __loop_count_(0), __open_count_(0), |
| 2509 | __end_(0), __left_anchor_(false) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2510 | {} |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2511 | 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] | 2512 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
| 2513 | __end_(0), __left_anchor_(false) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2514 | {__parse(__p, __p + __traits_.length(__p));} |
| 2515 | basic_regex(const value_type* __p, size_t __len, flag_type __f) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2516 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
| 2517 | __end_(0), __left_anchor_(false) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2518 | {__parse(__p, __p + __len);} |
| 2519 | basic_regex(const basic_regex&); |
| 2520 | #ifdef _LIBCPP_MOVE |
| 2521 | basic_regex(basic_regex&&); |
| 2522 | #endif |
| 2523 | template <class _ST, class _SA> |
| 2524 | explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p, |
| 2525 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2526 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
| 2527 | __end_(0), __left_anchor_(false) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2528 | {__parse(__p.begin(), __p.end());} |
| 2529 | template <class _ForwardIterator> |
| 2530 | basic_regex(_ForwardIterator __first, _ForwardIterator __last, |
| 2531 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2532 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
| 2533 | __end_(0), __left_anchor_(false) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2534 | {__parse(__first, __last);} |
| 2535 | basic_regex(initializer_list<value_type> __il, |
| 2536 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2537 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
| 2538 | __end_(0), __left_anchor_(false) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2539 | {__parse(__il.begin(), __il.end());} |
| 2540 | |
| 2541 | ~basic_regex(); |
| 2542 | |
| 2543 | basic_regex& operator=(const basic_regex&); |
| 2544 | #ifdef _LIBCPP_MOVE |
| 2545 | basic_regex& operator=(basic_regex&&); |
| 2546 | #endif |
| 2547 | basic_regex& operator=(const value_type* __p); |
| 2548 | basic_regex& operator=(initializer_list<value_type> __il); |
| 2549 | template <class _ST, class _SA> |
| 2550 | basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p); |
| 2551 | |
| 2552 | // assign: |
| 2553 | basic_regex& assign(const basic_regex& __that); |
| 2554 | #ifdef _LIBCPP_MOVE |
| 2555 | basic_regex& assign(basic_regex&& __that); |
| 2556 | #endif |
| 2557 | basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript); |
| 2558 | basic_regex& assign(const value_type* __p, size_t __len, flag_type __f); |
| 2559 | template <class _ST, class _SA> |
| 2560 | basic_regex& assign(const basic_string<value_type, _ST, _SA>& __s, |
| 2561 | flag_type __f = regex_constants::ECMAScript); |
| 2562 | template <class _InputIterator> |
| 2563 | basic_regex& assign(_InputIterator __first, _InputIterator __last, |
| 2564 | flag_type __f = regex_constants::ECMAScript); |
| 2565 | basic_regex& assign(initializer_list<value_type> __il, |
| 2566 | flag_type = regex_constants::ECMAScript); |
| 2567 | |
| 2568 | // const operations: |
| 2569 | unsigned mark_count() const {return __marked_count_;} |
| 2570 | flag_type flags() const {return __flags_;} |
| 2571 | |
| 2572 | // locale: |
| 2573 | locale_type imbue(locale_type __loc) {return __traits_.imbue(__loc);} |
| 2574 | locale_type getloc() const {return __traits_.getloc();} |
| 2575 | |
| 2576 | // swap: |
| 2577 | void swap(basic_regex&); |
| 2578 | |
| 2579 | private: |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2580 | unsigned __loop_count() const {return __loop_count_;} |
| 2581 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2582 | template <class _ForwardIterator> |
| 2583 | void __parse(_ForwardIterator __first, _ForwardIterator __last); |
| 2584 | template <class _ForwardIterator> |
| 2585 | _ForwardIterator |
| 2586 | __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2587 | template <class _ForwardIterator> |
| 2588 | _ForwardIterator |
| 2589 | __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2590 | template <class _ForwardIterator> |
| 2591 | _ForwardIterator |
| 2592 | __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2593 | template <class _ForwardIterator> |
| 2594 | _ForwardIterator |
| 2595 | __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2596 | template <class _ForwardIterator> |
| 2597 | _ForwardIterator |
| 2598 | __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2599 | template <class _ForwardIterator> |
| 2600 | _ForwardIterator |
| 2601 | __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last); |
| 2602 | template <class _ForwardIterator> |
| 2603 | _ForwardIterator |
| 2604 | __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last); |
| 2605 | template <class _ForwardIterator> |
| 2606 | _ForwardIterator |
| 2607 | __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last); |
| 2608 | template <class _ForwardIterator> |
| 2609 | _ForwardIterator |
| 2610 | __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last); |
| 2611 | template <class _ForwardIterator> |
| 2612 | _ForwardIterator |
| 2613 | __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last); |
| 2614 | template <class _ForwardIterator> |
| 2615 | _ForwardIterator |
| 2616 | __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last); |
| 2617 | template <class _ForwardIterator> |
| 2618 | _ForwardIterator |
| 2619 | __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last); |
| 2620 | template <class _ForwardIterator> |
| 2621 | _ForwardIterator |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2622 | __parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last, |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2623 | __owns_one_state<_CharT>* __s, |
| 2624 | unsigned __mexp_begin, unsigned __mexp_end); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2625 | template <class _ForwardIterator> |
| 2626 | _ForwardIterator |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 2627 | __parse_ERE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last, |
| 2628 | __owns_one_state<_CharT>* __s, |
| 2629 | unsigned __mexp_begin, unsigned __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2630 | template <class _ForwardIterator> |
| 2631 | _ForwardIterator |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2632 | __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2633 | template <class _ForwardIterator> |
| 2634 | _ForwardIterator |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2635 | __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last, |
| 2636 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2637 | template <class _ForwardIterator> |
| 2638 | _ForwardIterator |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2639 | __parse_expression_term(_ForwardIterator __first, _ForwardIterator __last, |
| 2640 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2641 | template <class _ForwardIterator> |
| 2642 | _ForwardIterator |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2643 | __parse_equivalence_class(_ForwardIterator __first, _ForwardIterator __last, |
| 2644 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2645 | template <class _ForwardIterator> |
| 2646 | _ForwardIterator |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2647 | __parse_character_class(_ForwardIterator __first, _ForwardIterator __last, |
| 2648 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2649 | template <class _ForwardIterator> |
| 2650 | _ForwardIterator |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2651 | __parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last, |
| 2652 | basic_string<_CharT>& __col_sym); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2653 | template <class _ForwardIterator> |
| 2654 | _ForwardIterator |
| 2655 | __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2656 | template <class _ForwardIterator> |
| 2657 | _ForwardIterator |
| 2658 | __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2659 | template <class _ForwardIterator> |
| 2660 | _ForwardIterator |
| 2661 | __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last); |
| 2662 | template <class _ForwardIterator> |
| 2663 | _ForwardIterator |
| 2664 | __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2665 | template <class _ForwardIterator> |
| 2666 | _ForwardIterator |
| 2667 | __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last); |
| 2668 | template <class _ForwardIterator> |
| 2669 | _ForwardIterator |
| 2670 | __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last); |
| 2671 | template <class _ForwardIterator> |
| 2672 | _ForwardIterator |
| 2673 | __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 2674 | template <class _ForwardIterator> |
| 2675 | _ForwardIterator |
| 2676 | __parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2677 | template <class _ForwardIterator> |
| 2678 | _ForwardIterator |
| 2679 | __parse_alternative(_ForwardIterator __first, _ForwardIterator __last); |
| 2680 | template <class _ForwardIterator> |
| 2681 | _ForwardIterator |
| 2682 | __parse_term(_ForwardIterator __first, _ForwardIterator __last); |
| 2683 | template <class _ForwardIterator> |
| 2684 | _ForwardIterator |
| 2685 | __parse_assertion(_ForwardIterator __first, _ForwardIterator __last); |
| 2686 | template <class _ForwardIterator> |
| 2687 | _ForwardIterator |
| 2688 | __parse_atom(_ForwardIterator __first, _ForwardIterator __last); |
| 2689 | template <class _ForwardIterator> |
| 2690 | _ForwardIterator |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2691 | __parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2692 | template <class _ForwardIterator> |
| 2693 | _ForwardIterator |
| 2694 | __parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2695 | template <class _ForwardIterator> |
| 2696 | _ForwardIterator |
| 2697 | __parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2698 | template <class _ForwardIterator> |
| 2699 | _ForwardIterator |
| 2700 | __parse_character_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2701 | template <class _ForwardIterator> |
| 2702 | _ForwardIterator |
| 2703 | __parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2704 | |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2705 | void __push_l_anchor() {__left_anchor_ = true;} |
| 2706 | void __push_r_anchor(); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2707 | void __push_match_any(); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2708 | void __push_match_any_but_newline(); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2709 | void __push_greedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s, |
| 2710 | unsigned __mexp_begin = 0, unsigned __mexp_end = 0) |
| 2711 | {__push_loop(__min, numeric_limits<size_t>::max(), __s, |
| 2712 | __mexp_begin, __mexp_end);} |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2713 | void __push_nongreedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s, |
| 2714 | unsigned __mexp_begin = 0, unsigned __mexp_end = 0) |
| 2715 | {__push_loop(__min, numeric_limits<size_t>::max(), __s, |
| 2716 | __mexp_begin, __mexp_end, false);} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2717 | void __push_loop(size_t __min, size_t __max, __owns_one_state<_CharT>* __s, |
| 2718 | size_t __mexp_begin = 0, size_t __mexp_end = 0, |
| 2719 | bool __greedy = true); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2720 | __bracket_expression<_CharT, _Traits>* __start_matching_list(bool __negate); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2721 | void __push_char(value_type __c); |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 2722 | void __push_back_ref(int __i); |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 2723 | void __push_alternation(__owns_one_state<_CharT>* __sa, |
| 2724 | __owns_one_state<_CharT>* __sb); |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2725 | void __push_begin_marked_subexpression(); |
| 2726 | void __push_end_marked_subexpression(unsigned); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 2727 | void __push_empty(); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2728 | void __push_word_boundary(bool); |
| 2729 | void __push_lookahead(bool) {} |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2730 | |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2731 | template <class _Allocator> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2732 | bool |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2733 | __search(const _CharT* __first, const _CharT* __last, |
| 2734 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2735 | regex_constants::match_flag_type __flags) const; |
| 2736 | |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2737 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2738 | bool |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2739 | __match_at_start(const _CharT* __first, const _CharT* __last, |
| 2740 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2741 | regex_constants::match_flag_type __flags) const; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2742 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2743 | bool |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2744 | __match_at_start_ecma(const _CharT* __first, const _CharT* __last, |
| 2745 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2746 | regex_constants::match_flag_type __flags) const; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2747 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2748 | bool |
| 2749 | __match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last, |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2750 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2751 | regex_constants::match_flag_type __flags) const; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2752 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2753 | bool |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2754 | __match_at_start_posix_subs(const _CharT* __first, const _CharT* __last, |
| 2755 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2756 | regex_constants::match_flag_type __flags) const; |
| 2757 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2758 | template <class _B, class _A, class _C, class _T> |
| 2759 | friend |
| 2760 | bool |
| 2761 | regex_search(_B, _B, match_results<_B, _A>&, const basic_regex<_C, _T>&, |
| 2762 | regex_constants::match_flag_type); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2763 | |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2764 | template <class _A, class _C, class _T> |
| 2765 | friend |
| 2766 | bool |
| 2767 | regex_search(const _C*, const _C*, match_results<const _C*, _A>&, |
| 2768 | const basic_regex<_C, _T>&, regex_constants::match_flag_type); |
| 2769 | |
| 2770 | template <class _B, class _C, class _T> |
| 2771 | friend |
| 2772 | bool |
| 2773 | regex_search(_B, _B, const basic_regex<_C, _T>&, |
| 2774 | regex_constants::match_flag_type); |
| 2775 | |
| 2776 | template <class _C, class _T> |
| 2777 | friend |
| 2778 | bool |
| 2779 | regex_search(const _C*, const _C*, |
| 2780 | const basic_regex<_C, _T>&, regex_constants::match_flag_type); |
| 2781 | |
| 2782 | template <class _C, class _A, class _T> |
| 2783 | friend |
| 2784 | bool |
| 2785 | regex_search(const _C*, match_results<const _C*, _A>&, const basic_regex<_C, _T>&, |
| 2786 | regex_constants::match_flag_type); |
| 2787 | |
| 2788 | template <class _ST, class _SA, class _C, class _T> |
| 2789 | friend |
| 2790 | bool |
| 2791 | regex_search(const basic_string<_C, _ST, _SA>& __s, |
| 2792 | const basic_regex<_C, _T>& __e, |
| 2793 | regex_constants::match_flag_type __flags); |
| 2794 | |
| 2795 | template <class _ST, class _SA, class _A, class _C, class _T> |
| 2796 | friend |
| 2797 | bool |
| 2798 | regex_search(const basic_string<_C, _ST, _SA>& __s, |
| 2799 | match_results<typename basic_string<_C, _ST, _SA>::const_iterator, _A>&, |
| 2800 | const basic_regex<_C, _T>& __e, |
| 2801 | regex_constants::match_flag_type __flags); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2802 | }; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2803 | |
| 2804 | template <class _CharT, class _Traits> |
| 2805 | basic_regex<_CharT, _Traits>::~basic_regex() |
| 2806 | { |
| 2807 | } |
| 2808 | |
| 2809 | template <class _CharT, class _Traits> |
| 2810 | template <class _ForwardIterator> |
| 2811 | void |
| 2812 | basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first, |
| 2813 | _ForwardIterator __last) |
| 2814 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2815 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2816 | unique_ptr<__node> __h(new __end_state<_CharT>); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2817 | __start_.reset(new __empty_state<_CharT>(__h.get())); |
| 2818 | __h.release(); |
| 2819 | __end_ = __start_.get(); |
| 2820 | } |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame^] | 2821 | switch (__flags_ & 0x1F0) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2822 | { |
| 2823 | case ECMAScript: |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 2824 | __parse_ecma_exp(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2825 | break; |
| 2826 | case basic: |
| 2827 | __parse_basic_reg_exp(__first, __last); |
| 2828 | break; |
| 2829 | case extended: |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2830 | __parse_extended_reg_exp(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2831 | break; |
| 2832 | case awk: |
| 2833 | break; |
| 2834 | case grep: |
| 2835 | break; |
| 2836 | case egrep: |
| 2837 | break; |
| 2838 | default: |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame^] | 2839 | throw regex_error(regex_constants::__re_err_grammar); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2840 | } |
| 2841 | } |
| 2842 | |
| 2843 | template <class _CharT, class _Traits> |
| 2844 | template <class _ForwardIterator> |
| 2845 | _ForwardIterator |
| 2846 | basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first, |
| 2847 | _ForwardIterator __last) |
| 2848 | { |
| 2849 | if (__first != __last) |
| 2850 | { |
| 2851 | if (*__first == '^') |
| 2852 | { |
| 2853 | __push_l_anchor(); |
| 2854 | ++__first; |
| 2855 | } |
| 2856 | if (__first != __last) |
| 2857 | { |
| 2858 | __first = __parse_RE_expression(__first, __last); |
| 2859 | if (__first != __last) |
| 2860 | { |
| 2861 | _ForwardIterator __temp = next(__first); |
| 2862 | if (__temp == __last && *__first == '$') |
| 2863 | { |
| 2864 | __push_r_anchor(); |
| 2865 | ++__first; |
| 2866 | } |
| 2867 | } |
| 2868 | } |
| 2869 | if (__first != __last) |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame^] | 2870 | throw regex_error(regex_constants::__re_err_empty); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2871 | } |
| 2872 | return __first; |
| 2873 | } |
| 2874 | |
| 2875 | template <class _CharT, class _Traits> |
| 2876 | template <class _ForwardIterator> |
| 2877 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2878 | basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first, |
| 2879 | _ForwardIterator __last) |
| 2880 | { |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 2881 | __owns_one_state<_CharT>* __sa = __end_; |
| 2882 | _ForwardIterator __temp = __parse_ERE_branch(__first, __last); |
| 2883 | if (__temp == __first) |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame^] | 2884 | throw regex_error(regex_constants::__re_err_empty); |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 2885 | __first = __temp; |
| 2886 | while (__first != __last && *__first == '|') |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2887 | { |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 2888 | __owns_one_state<_CharT>* __sb = __end_; |
| 2889 | __temp = __parse_ERE_branch(++__first, __last); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2890 | if (__temp == __first) |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame^] | 2891 | throw regex_error(regex_constants::__re_err_empty); |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 2892 | __push_alternation(__sa, __sb); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2893 | __first = __temp; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2894 | } |
| 2895 | return __first; |
| 2896 | } |
| 2897 | |
| 2898 | template <class _CharT, class _Traits> |
| 2899 | template <class _ForwardIterator> |
| 2900 | _ForwardIterator |
| 2901 | basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first, |
| 2902 | _ForwardIterator __last) |
| 2903 | { |
| 2904 | _ForwardIterator __temp = __parse_ERE_expression(__first, __last); |
| 2905 | if (__temp == __first) |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame^] | 2906 | throw regex_error(regex_constants::__re_err_empty); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2907 | do |
| 2908 | { |
| 2909 | __first = __temp; |
| 2910 | __temp = __parse_ERE_expression(__first, __last); |
| 2911 | } while (__temp != __first); |
| 2912 | return __first; |
| 2913 | } |
| 2914 | |
| 2915 | template <class _CharT, class _Traits> |
| 2916 | template <class _ForwardIterator> |
| 2917 | _ForwardIterator |
| 2918 | basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first, |
| 2919 | _ForwardIterator __last) |
| 2920 | { |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 2921 | __owns_one_state<_CharT>* __e = __end_; |
| 2922 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2923 | _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last); |
| 2924 | if (__temp == __first && __temp != __last) |
| 2925 | { |
| 2926 | switch (*__temp) |
| 2927 | { |
| 2928 | case '^': |
| 2929 | __push_l_anchor(); |
| 2930 | ++__temp; |
| 2931 | break; |
| 2932 | case '$': |
| 2933 | __push_r_anchor(); |
| 2934 | ++__temp; |
| 2935 | break; |
| 2936 | case '(': |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2937 | __push_begin_marked_subexpression(); |
| 2938 | unsigned __temp_count = __marked_count_; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2939 | ++__open_count_; |
| 2940 | __temp = __parse_extended_reg_exp(++__temp, __last); |
| 2941 | if (__temp == __last || *__temp != ')') |
| 2942 | throw regex_error(regex_constants::error_paren); |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2943 | __push_end_marked_subexpression(__temp_count); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2944 | --__open_count_; |
| 2945 | ++__temp; |
| 2946 | break; |
| 2947 | } |
| 2948 | } |
| 2949 | if (__temp != __first) |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 2950 | __temp = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin+1, |
| 2951 | __marked_count_+1); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2952 | __first = __temp; |
| 2953 | return __first; |
| 2954 | } |
| 2955 | |
| 2956 | template <class _CharT, class _Traits> |
| 2957 | template <class _ForwardIterator> |
| 2958 | _ForwardIterator |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2959 | basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first, |
| 2960 | _ForwardIterator __last) |
| 2961 | { |
| 2962 | while (true) |
| 2963 | { |
| 2964 | _ForwardIterator __temp = __parse_simple_RE(__first, __last); |
| 2965 | if (__temp == __first) |
| 2966 | break; |
| 2967 | __first = __temp; |
| 2968 | } |
| 2969 | return __first; |
| 2970 | } |
| 2971 | |
| 2972 | template <class _CharT, class _Traits> |
| 2973 | template <class _ForwardIterator> |
| 2974 | _ForwardIterator |
| 2975 | basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first, |
| 2976 | _ForwardIterator __last) |
| 2977 | { |
| 2978 | if (__first != __last) |
| 2979 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2980 | __owns_one_state<_CharT>* __e = __end_; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2981 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2982 | _ForwardIterator __temp = __parse_nondupl_RE(__first, __last); |
| 2983 | if (__temp != __first) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2984 | __first = __parse_RE_dupl_symbol(__temp, __last, __e, |
| 2985 | __mexp_begin+1, __marked_count_+1); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2986 | } |
| 2987 | return __first; |
| 2988 | } |
| 2989 | |
| 2990 | template <class _CharT, class _Traits> |
| 2991 | template <class _ForwardIterator> |
| 2992 | _ForwardIterator |
| 2993 | basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first, |
| 2994 | _ForwardIterator __last) |
| 2995 | { |
| 2996 | _ForwardIterator __temp = __first; |
| 2997 | __first = __parse_one_char_or_coll_elem_RE(__first, __last); |
| 2998 | if (__temp == __first) |
| 2999 | { |
| 3000 | __temp = __parse_Back_open_paren(__first, __last); |
| 3001 | if (__temp != __first) |
| 3002 | { |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3003 | __push_begin_marked_subexpression(); |
| 3004 | unsigned __temp_count = __marked_count_; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3005 | __first = __parse_RE_expression(__temp, __last); |
| 3006 | __temp = __parse_Back_close_paren(__first, __last); |
| 3007 | if (__temp == __first) |
| 3008 | throw regex_error(regex_constants::error_paren); |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3009 | __push_end_marked_subexpression(__temp_count); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3010 | __first = __temp; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3011 | } |
| 3012 | else |
| 3013 | __first = __parse_BACKREF(__first, __last); |
| 3014 | } |
| 3015 | return __first; |
| 3016 | } |
| 3017 | |
| 3018 | template <class _CharT, class _Traits> |
| 3019 | template <class _ForwardIterator> |
| 3020 | _ForwardIterator |
| 3021 | basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE( |
| 3022 | _ForwardIterator __first, |
| 3023 | _ForwardIterator __last) |
| 3024 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3025 | _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3026 | if (__temp == __first) |
| 3027 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3028 | __temp = __parse_QUOTED_CHAR(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3029 | if (__temp == __first) |
| 3030 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3031 | if (__temp != __last && *__temp == '.') |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3032 | { |
| 3033 | __push_match_any(); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3034 | ++__temp; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3035 | } |
| 3036 | else |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3037 | __temp = __parse_bracket_expression(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3038 | } |
| 3039 | } |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3040 | __first = __temp; |
| 3041 | return __first; |
| 3042 | } |
| 3043 | |
| 3044 | template <class _CharT, class _Traits> |
| 3045 | template <class _ForwardIterator> |
| 3046 | _ForwardIterator |
| 3047 | basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE( |
| 3048 | _ForwardIterator __first, |
| 3049 | _ForwardIterator __last) |
| 3050 | { |
| 3051 | _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last); |
| 3052 | if (__temp == __first) |
| 3053 | { |
| 3054 | __temp = __parse_QUOTED_CHAR_ERE(__first, __last); |
| 3055 | if (__temp == __first) |
| 3056 | { |
| 3057 | if (__temp != __last && *__temp == '.') |
| 3058 | { |
| 3059 | __push_match_any(); |
| 3060 | ++__temp; |
| 3061 | } |
| 3062 | else |
| 3063 | __temp = __parse_bracket_expression(__first, __last); |
| 3064 | } |
| 3065 | } |
| 3066 | __first = __temp; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3067 | return __first; |
| 3068 | } |
| 3069 | |
| 3070 | template <class _CharT, class _Traits> |
| 3071 | template <class _ForwardIterator> |
| 3072 | _ForwardIterator |
| 3073 | basic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first, |
| 3074 | _ForwardIterator __last) |
| 3075 | { |
| 3076 | if (__first != __last) |
| 3077 | { |
| 3078 | _ForwardIterator __temp = next(__first); |
| 3079 | if (__temp != __last) |
| 3080 | { |
| 3081 | if (*__first == '\\' && *__temp == '(') |
| 3082 | __first = ++__temp; |
| 3083 | } |
| 3084 | } |
| 3085 | return __first; |
| 3086 | } |
| 3087 | |
| 3088 | template <class _CharT, class _Traits> |
| 3089 | template <class _ForwardIterator> |
| 3090 | _ForwardIterator |
| 3091 | basic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first, |
| 3092 | _ForwardIterator __last) |
| 3093 | { |
| 3094 | if (__first != __last) |
| 3095 | { |
| 3096 | _ForwardIterator __temp = next(__first); |
| 3097 | if (__temp != __last) |
| 3098 | { |
| 3099 | if (*__first == '\\' && *__temp == ')') |
| 3100 | __first = ++__temp; |
| 3101 | } |
| 3102 | } |
| 3103 | return __first; |
| 3104 | } |
| 3105 | |
| 3106 | template <class _CharT, class _Traits> |
| 3107 | template <class _ForwardIterator> |
| 3108 | _ForwardIterator |
| 3109 | basic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first, |
| 3110 | _ForwardIterator __last) |
| 3111 | { |
| 3112 | if (__first != __last) |
| 3113 | { |
| 3114 | _ForwardIterator __temp = next(__first); |
| 3115 | if (__temp != __last) |
| 3116 | { |
| 3117 | if (*__first == '\\' && *__temp == '{') |
| 3118 | __first = ++__temp; |
| 3119 | } |
| 3120 | } |
| 3121 | return __first; |
| 3122 | } |
| 3123 | |
| 3124 | template <class _CharT, class _Traits> |
| 3125 | template <class _ForwardIterator> |
| 3126 | _ForwardIterator |
| 3127 | basic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first, |
| 3128 | _ForwardIterator __last) |
| 3129 | { |
| 3130 | if (__first != __last) |
| 3131 | { |
| 3132 | _ForwardIterator __temp = next(__first); |
| 3133 | if (__temp != __last) |
| 3134 | { |
| 3135 | if (*__first == '\\' && *__temp == '}') |
| 3136 | __first = ++__temp; |
| 3137 | } |
| 3138 | } |
| 3139 | return __first; |
| 3140 | } |
| 3141 | |
| 3142 | template <class _CharT, class _Traits> |
| 3143 | template <class _ForwardIterator> |
| 3144 | _ForwardIterator |
| 3145 | basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first, |
| 3146 | _ForwardIterator __last) |
| 3147 | { |
| 3148 | if (__first != __last) |
| 3149 | { |
| 3150 | _ForwardIterator __temp = next(__first); |
| 3151 | if (__temp != __last) |
| 3152 | { |
| 3153 | if (*__first == '\\' && '1' <= *__temp && *__temp <= '9') |
| 3154 | { |
| 3155 | __push_back_ref(*__temp - '0'); |
| 3156 | __first = ++__temp; |
| 3157 | } |
| 3158 | } |
| 3159 | } |
| 3160 | return __first; |
| 3161 | } |
| 3162 | |
| 3163 | template <class _CharT, class _Traits> |
| 3164 | template <class _ForwardIterator> |
| 3165 | _ForwardIterator |
| 3166 | basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first, |
| 3167 | _ForwardIterator __last) |
| 3168 | { |
| 3169 | if (__first != __last) |
| 3170 | { |
| 3171 | _ForwardIterator __temp = next(__first); |
| 3172 | if (__temp == __last && *__first == '$') |
| 3173 | return __first; |
| 3174 | // Not called inside a bracket |
| 3175 | if (*__first == '.' || *__first == '\\' || *__first == '[') |
| 3176 | return __first; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3177 | __push_char(*__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3178 | ++__first; |
| 3179 | } |
| 3180 | return __first; |
| 3181 | } |
| 3182 | |
| 3183 | template <class _CharT, class _Traits> |
| 3184 | template <class _ForwardIterator> |
| 3185 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3186 | basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first, |
| 3187 | _ForwardIterator __last) |
| 3188 | { |
| 3189 | if (__first != __last) |
| 3190 | { |
| 3191 | switch (*__first) |
| 3192 | { |
| 3193 | case '^': |
| 3194 | case '.': |
| 3195 | case '[': |
| 3196 | case '$': |
| 3197 | case '(': |
| 3198 | case '|': |
| 3199 | case '*': |
| 3200 | case '+': |
| 3201 | case '?': |
| 3202 | case '{': |
| 3203 | case '\\': |
| 3204 | break; |
| 3205 | case ')': |
| 3206 | if (__open_count_ == 0) |
| 3207 | { |
| 3208 | __push_char(*__first); |
| 3209 | ++__first; |
| 3210 | } |
| 3211 | break; |
| 3212 | default: |
| 3213 | __push_char(*__first); |
| 3214 | ++__first; |
| 3215 | break; |
| 3216 | } |
| 3217 | } |
| 3218 | return __first; |
| 3219 | } |
| 3220 | |
| 3221 | template <class _CharT, class _Traits> |
| 3222 | template <class _ForwardIterator> |
| 3223 | _ForwardIterator |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3224 | basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first, |
| 3225 | _ForwardIterator __last) |
| 3226 | { |
| 3227 | if (__first != __last) |
| 3228 | { |
| 3229 | _ForwardIterator __temp = next(__first); |
| 3230 | if (__temp != __last) |
| 3231 | { |
| 3232 | if (*__first == '\\') |
| 3233 | { |
| 3234 | switch (*__temp) |
| 3235 | { |
| 3236 | case '^': |
| 3237 | case '.': |
| 3238 | case '*': |
| 3239 | case '[': |
| 3240 | case '$': |
| 3241 | case '\\': |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3242 | __push_char(*__temp); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3243 | __first = ++__temp; |
| 3244 | break; |
| 3245 | } |
| 3246 | } |
| 3247 | } |
| 3248 | } |
| 3249 | return __first; |
| 3250 | } |
| 3251 | |
| 3252 | template <class _CharT, class _Traits> |
| 3253 | template <class _ForwardIterator> |
| 3254 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3255 | basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first, |
| 3256 | _ForwardIterator __last) |
| 3257 | { |
| 3258 | if (__first != __last) |
| 3259 | { |
| 3260 | _ForwardIterator __temp = next(__first); |
| 3261 | if (__temp != __last) |
| 3262 | { |
| 3263 | if (*__first == '\\') |
| 3264 | { |
| 3265 | switch (*__temp) |
| 3266 | { |
| 3267 | case '^': |
| 3268 | case '.': |
| 3269 | case '*': |
| 3270 | case '[': |
| 3271 | case '$': |
| 3272 | case '\\': |
| 3273 | case '(': |
| 3274 | case ')': |
| 3275 | case '|': |
| 3276 | case '+': |
| 3277 | case '?': |
| 3278 | case '{': |
| 3279 | __push_char(*__temp); |
| 3280 | __first = ++__temp; |
| 3281 | break; |
| 3282 | } |
| 3283 | } |
| 3284 | } |
| 3285 | } |
| 3286 | return __first; |
| 3287 | } |
| 3288 | |
| 3289 | template <class _CharT, class _Traits> |
| 3290 | template <class _ForwardIterator> |
| 3291 | _ForwardIterator |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3292 | basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3293 | _ForwardIterator __last, |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3294 | __owns_one_state<_CharT>* __s, |
| 3295 | unsigned __mexp_begin, |
| 3296 | unsigned __mexp_end) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3297 | { |
| 3298 | if (__first != __last) |
| 3299 | { |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3300 | if (*__first == '*') |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3301 | { |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3302 | __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3303 | ++__first; |
| 3304 | } |
| 3305 | else |
| 3306 | { |
| 3307 | _ForwardIterator __temp = __parse_Back_open_brace(__first, __last); |
| 3308 | if (__temp != __first) |
| 3309 | { |
| 3310 | int __min = 0; |
| 3311 | __first = __temp; |
| 3312 | __temp = __parse_DUP_COUNT(__first, __last, __min); |
| 3313 | if (__temp == __first) |
| 3314 | throw regex_error(regex_constants::error_badbrace); |
| 3315 | __first = __temp; |
| 3316 | if (__first == __last) |
| 3317 | throw regex_error(regex_constants::error_brace); |
| 3318 | if (*__first != ',') |
| 3319 | { |
| 3320 | __temp = __parse_Back_close_brace(__first, __last); |
| 3321 | if (__temp == __first) |
| 3322 | throw regex_error(regex_constants::error_brace); |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 3323 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, |
| 3324 | true); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3325 | __first = __temp; |
| 3326 | } |
| 3327 | else |
| 3328 | { |
| 3329 | ++__first; // consume ',' |
| 3330 | int __max = -1; |
| 3331 | __first = __parse_DUP_COUNT(__first, __last, __max); |
| 3332 | __temp = __parse_Back_close_brace(__first, __last); |
| 3333 | if (__temp == __first) |
| 3334 | throw regex_error(regex_constants::error_brace); |
| 3335 | if (__max == -1) |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3336 | __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3337 | else |
| 3338 | { |
| 3339 | if (__max < __min) |
| 3340 | throw regex_error(regex_constants::error_badbrace); |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 3341 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, |
| 3342 | true); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3343 | } |
| 3344 | __first = __temp; |
| 3345 | } |
| 3346 | } |
| 3347 | } |
| 3348 | } |
| 3349 | return __first; |
| 3350 | } |
| 3351 | |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3352 | template <class _CharT, class _Traits> |
| 3353 | template <class _ForwardIterator> |
| 3354 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3355 | basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first, |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3356 | _ForwardIterator __last, |
| 3357 | __owns_one_state<_CharT>* __s, |
| 3358 | unsigned __mexp_begin, |
| 3359 | unsigned __mexp_end) |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3360 | { |
| 3361 | if (__first != __last) |
| 3362 | { |
| 3363 | switch (*__first) |
| 3364 | { |
| 3365 | case '*': |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3366 | ++__first; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3367 | if ((__flags_ & ECMAScript) && __first != __last && *__first == '?') |
| 3368 | { |
| 3369 | ++__first; |
| 3370 | __push_nongreedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
| 3371 | } |
| 3372 | else |
| 3373 | __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3374 | break; |
| 3375 | case '+': |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3376 | ++__first; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3377 | if ((__flags_ & ECMAScript) && __first != __last && *__first == '?') |
| 3378 | { |
| 3379 | ++__first; |
| 3380 | __push_nongreedy_inf_repeat(1, __s, __mexp_begin, __mexp_end); |
| 3381 | } |
| 3382 | else |
| 3383 | __push_greedy_inf_repeat(1, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3384 | break; |
| 3385 | case '?': |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3386 | ++__first; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3387 | if ((__flags_ & ECMAScript) && __first != __last && *__first == '?') |
| 3388 | { |
| 3389 | ++__first; |
| 3390 | __push_loop(0, 1, __s, __mexp_begin, __mexp_end, false); |
| 3391 | } |
| 3392 | else |
| 3393 | __push_loop(0, 1, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3394 | break; |
| 3395 | case '{': |
| 3396 | { |
| 3397 | int __min; |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3398 | _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3399 | if (__temp == __first) |
| 3400 | throw regex_error(regex_constants::error_badbrace); |
| 3401 | __first = __temp; |
| 3402 | if (__first == __last) |
| 3403 | throw regex_error(regex_constants::error_brace); |
| 3404 | switch (*__first) |
| 3405 | { |
| 3406 | case '}': |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3407 | ++__first; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3408 | if ((__flags_ & ECMAScript) && __first != __last && *__first == '?') |
| 3409 | { |
| 3410 | ++__first; |
| 3411 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, false); |
| 3412 | } |
| 3413 | else |
| 3414 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3415 | break; |
| 3416 | case ',': |
| 3417 | if (++__first == __last) |
| 3418 | throw regex_error(regex_constants::error_badbrace); |
| 3419 | if (*__first == '}') |
| 3420 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3421 | ++__first; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3422 | if ((__flags_ & ECMAScript) && __first != __last && *__first == '?') |
| 3423 | { |
| 3424 | ++__first; |
| 3425 | __push_nongreedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
| 3426 | } |
| 3427 | else |
| 3428 | __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3429 | } |
| 3430 | else |
| 3431 | { |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3432 | int __max = -1; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3433 | __temp = __parse_DUP_COUNT(__first, __last, __max); |
| 3434 | if (__temp == __first) |
| 3435 | throw regex_error(regex_constants::error_brace); |
| 3436 | __first = __temp; |
| 3437 | if (__first == __last || *__first != '}') |
| 3438 | throw regex_error(regex_constants::error_brace); |
| 3439 | ++__first; |
| 3440 | if (__max < __min) |
| 3441 | throw regex_error(regex_constants::error_badbrace); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3442 | if ((__flags_ & ECMAScript) && __first != __last && *__first == '?') |
| 3443 | { |
| 3444 | ++__first; |
| 3445 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, false); |
| 3446 | } |
| 3447 | else |
| 3448 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3449 | } |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3450 | break; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3451 | default: |
| 3452 | throw regex_error(regex_constants::error_badbrace); |
| 3453 | } |
| 3454 | } |
| 3455 | break; |
| 3456 | } |
| 3457 | } |
| 3458 | return __first; |
| 3459 | } |
| 3460 | |
| 3461 | template <class _CharT, class _Traits> |
| 3462 | template <class _ForwardIterator> |
| 3463 | _ForwardIterator |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3464 | basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first, |
| 3465 | _ForwardIterator __last) |
| 3466 | { |
| 3467 | if (__first != __last && *__first == '[') |
| 3468 | { |
| 3469 | if (++__first == __last) |
| 3470 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3471 | bool __negate = false; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3472 | if (*__first == '^') |
| 3473 | { |
| 3474 | ++__first; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3475 | __negate = true; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3476 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3477 | __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate); |
| 3478 | // __ml owned by *this |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3479 | if (__first == __last) |
| 3480 | throw regex_error(regex_constants::error_brack); |
| 3481 | if (*__first == ']') |
| 3482 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3483 | __ml->__add_char(']'); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3484 | ++__first; |
| 3485 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3486 | __first = __parse_follow_list(__first, __last, __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3487 | if (__first == __last) |
| 3488 | throw regex_error(regex_constants::error_brack); |
| 3489 | if (*__first == '-') |
| 3490 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3491 | __ml->__add_char('-'); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3492 | ++__first; |
| 3493 | } |
| 3494 | if (__first == __last || *__first != ']') |
| 3495 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3496 | ++__first; |
| 3497 | } |
| 3498 | return __first; |
| 3499 | } |
| 3500 | |
| 3501 | template <class _CharT, class _Traits> |
| 3502 | template <class _ForwardIterator> |
| 3503 | _ForwardIterator |
| 3504 | basic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3505 | _ForwardIterator __last, |
| 3506 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3507 | { |
| 3508 | if (__first != __last) |
| 3509 | { |
| 3510 | while (true) |
| 3511 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3512 | _ForwardIterator __temp = __parse_expression_term(__first, __last, |
| 3513 | __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3514 | if (__temp == __first) |
| 3515 | break; |
| 3516 | __first = __temp; |
| 3517 | } |
| 3518 | } |
| 3519 | return __first; |
| 3520 | } |
| 3521 | |
| 3522 | template <class _CharT, class _Traits> |
| 3523 | template <class _ForwardIterator> |
| 3524 | _ForwardIterator |
| 3525 | basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3526 | _ForwardIterator __last, |
| 3527 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3528 | { |
| 3529 | if (__first != __last && *__first != ']') |
| 3530 | { |
| 3531 | bool __parsed_one = false; |
| 3532 | _ForwardIterator __temp = next(__first); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3533 | basic_string<_CharT> __start_range; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3534 | if (__temp != __last && *__first == '[') |
| 3535 | { |
| 3536 | if (*__temp == '=') |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3537 | return __parse_equivalence_class(++__temp, __last, __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3538 | else if (*__temp == ':') |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3539 | return __parse_character_class(++__temp, __last, __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3540 | else if (*__temp == '.') |
| 3541 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3542 | __first = __parse_collating_symbol(++__temp, __last, __start_range); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3543 | __parsed_one = true; |
| 3544 | } |
| 3545 | } |
| 3546 | if (!__parsed_one) |
| 3547 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3548 | __start_range = *__first; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3549 | ++__first; |
| 3550 | } |
| 3551 | if (__first != __last && *__first != ']') |
| 3552 | { |
| 3553 | __temp = next(__first); |
| 3554 | if (__temp != __last && *__first == '-' && *__temp != ']') |
| 3555 | { |
| 3556 | // parse a range |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3557 | basic_string<_CharT> __end_range; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3558 | __first = __temp; |
| 3559 | ++__temp; |
| 3560 | if (__temp != __last && *__first == '[' && *__temp == '.') |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3561 | __first = __parse_collating_symbol(++__temp, __last, __end_range); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3562 | else |
| 3563 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3564 | __end_range = *__first; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3565 | ++__first; |
| 3566 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3567 | __ml->__add_range(_STD::move(__start_range), _STD::move(__end_range)); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3568 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3569 | else |
| 3570 | { |
| 3571 | if (__start_range.size() == 1) |
| 3572 | __ml->__add_char(__start_range[0]); |
| 3573 | else |
| 3574 | __ml->__add_digraph(__start_range[0], __start_range[1]); |
| 3575 | } |
| 3576 | } |
| 3577 | else |
| 3578 | { |
| 3579 | if (__start_range.size() == 1) |
| 3580 | __ml->__add_char(__start_range[0]); |
| 3581 | else |
| 3582 | __ml->__add_digraph(__start_range[0], __start_range[1]); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3583 | } |
| 3584 | } |
| 3585 | return __first; |
| 3586 | } |
| 3587 | |
| 3588 | template <class _CharT, class _Traits> |
| 3589 | template <class _ForwardIterator> |
| 3590 | _ForwardIterator |
| 3591 | basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3592 | _ForwardIterator __last, |
| 3593 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3594 | { |
| 3595 | // Found [= |
| 3596 | // This means =] must exist |
| 3597 | value_type _Equal_close[2] = {'=', ']'}; |
| 3598 | _ForwardIterator __temp = _STD::search(__first, __last, _Equal_close, |
| 3599 | _Equal_close+2); |
| 3600 | if (__temp == __last) |
| 3601 | throw regex_error(regex_constants::error_brack); |
| 3602 | // [__first, __temp) contains all text in [= ... =] |
| 3603 | typedef typename _Traits::string_type string_type; |
| 3604 | string_type __collate_name = |
| 3605 | __traits_.lookup_collatename(__first, __temp); |
| 3606 | if (__collate_name.empty()) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3607 | throw regex_error(regex_constants::error_collate); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3608 | string_type __equiv_name = |
| 3609 | __traits_.transform_primary(__collate_name.begin(), |
| 3610 | __collate_name.end()); |
| 3611 | if (!__equiv_name.empty()) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3612 | __ml->__add_equivalence(__equiv_name); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3613 | else |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3614 | { |
| 3615 | switch (__collate_name.size()) |
| 3616 | { |
| 3617 | case 1: |
| 3618 | __ml->__add_char(__collate_name[0]); |
| 3619 | break; |
| 3620 | case 2: |
| 3621 | __ml->__add_digraph(__collate_name[0], __collate_name[1]); |
| 3622 | break; |
| 3623 | default: |
| 3624 | throw regex_error(regex_constants::error_collate); |
| 3625 | } |
| 3626 | } |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3627 | __first = next(__temp, 2); |
| 3628 | return __first; |
| 3629 | } |
| 3630 | |
| 3631 | template <class _CharT, class _Traits> |
| 3632 | template <class _ForwardIterator> |
| 3633 | _ForwardIterator |
| 3634 | basic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3635 | _ForwardIterator __last, |
| 3636 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3637 | { |
| 3638 | // Found [: |
| 3639 | // This means :] must exist |
| 3640 | value_type _Colon_close[2] = {':', ']'}; |
| 3641 | _ForwardIterator __temp = _STD::search(__first, __last, _Colon_close, |
| 3642 | _Colon_close+2); |
| 3643 | if (__temp == __last) |
| 3644 | throw regex_error(regex_constants::error_brack); |
| 3645 | // [__first, __temp) contains all text in [: ... :] |
| 3646 | typedef typename _Traits::char_class_type char_class_type; |
| 3647 | char_class_type __class_type = |
| 3648 | __traits_.lookup_classname(__first, __temp, __flags_ & icase); |
| 3649 | if (__class_type == 0) |
| 3650 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3651 | __ml->__add_class(__class_type); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3652 | __first = next(__temp, 2); |
| 3653 | return __first; |
| 3654 | } |
| 3655 | |
| 3656 | template <class _CharT, class _Traits> |
| 3657 | template <class _ForwardIterator> |
| 3658 | _ForwardIterator |
| 3659 | basic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3660 | _ForwardIterator __last, |
| 3661 | basic_string<_CharT>& __col_sym) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3662 | { |
| 3663 | // Found [. |
| 3664 | // This means .] must exist |
| 3665 | value_type _Dot_close[2] = {'.', ']'}; |
| 3666 | _ForwardIterator __temp = _STD::search(__first, __last, _Dot_close, |
| 3667 | _Dot_close+2); |
| 3668 | if (__temp == __last) |
| 3669 | throw regex_error(regex_constants::error_brack); |
| 3670 | // [__first, __temp) contains all text in [. ... .] |
| 3671 | typedef typename _Traits::string_type string_type; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3672 | __col_sym = __traits_.lookup_collatename(__first, __temp); |
| 3673 | switch (__col_sym.size()) |
| 3674 | { |
| 3675 | case 1: |
| 3676 | case 2: |
| 3677 | break; |
| 3678 | default: |
| 3679 | throw regex_error(regex_constants::error_collate); |
| 3680 | } |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3681 | __first = next(__temp, 2); |
| 3682 | return __first; |
| 3683 | } |
| 3684 | |
| 3685 | template <class _CharT, class _Traits> |
| 3686 | template <class _ForwardIterator> |
| 3687 | _ForwardIterator |
| 3688 | basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first, |
| 3689 | _ForwardIterator __last, |
| 3690 | int& __c) |
| 3691 | { |
| 3692 | if (__first != __last && '0' <= *__first && *__first <= '9') |
| 3693 | { |
| 3694 | __c = *__first - '0'; |
| 3695 | for (++__first; __first != __last && '0' <= *__first && *__first <= '9'; |
| 3696 | ++__first) |
| 3697 | { |
| 3698 | __c *= 10; |
| 3699 | __c += *__first - '0'; |
| 3700 | } |
| 3701 | } |
| 3702 | return __first; |
| 3703 | } |
| 3704 | |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3705 | template <class _CharT, class _Traits> |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 3706 | template <class _ForwardIterator> |
| 3707 | _ForwardIterator |
| 3708 | basic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first, |
| 3709 | _ForwardIterator __last) |
| 3710 | { |
| 3711 | __owns_one_state<_CharT>* __sa = __end_; |
| 3712 | _ForwardIterator __temp = __parse_alternative(__first, __last); |
| 3713 | if (__temp == __first) |
| 3714 | __push_empty(); |
| 3715 | __first = __temp; |
| 3716 | while (__first != __last && *__first == '|') |
| 3717 | { |
| 3718 | __owns_one_state<_CharT>* __sb = __end_; |
| 3719 | __temp = __parse_alternative(++__first, __last); |
| 3720 | if (__temp == __first) |
| 3721 | __push_empty(); |
| 3722 | __push_alternation(__sa, __sb); |
| 3723 | __first = __temp; |
| 3724 | } |
| 3725 | return __first; |
| 3726 | } |
| 3727 | |
| 3728 | template <class _CharT, class _Traits> |
| 3729 | template <class _ForwardIterator> |
| 3730 | _ForwardIterator |
| 3731 | basic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first, |
| 3732 | _ForwardIterator __last) |
| 3733 | { |
| 3734 | while (true) |
| 3735 | { |
| 3736 | _ForwardIterator __temp = __parse_term(__first, __last); |
| 3737 | if (__temp == __first) |
| 3738 | break; |
| 3739 | __first = __temp; |
| 3740 | } |
| 3741 | return __first; |
| 3742 | } |
| 3743 | |
| 3744 | template <class _CharT, class _Traits> |
| 3745 | template <class _ForwardIterator> |
| 3746 | _ForwardIterator |
| 3747 | basic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first, |
| 3748 | _ForwardIterator __last) |
| 3749 | { |
| 3750 | _ForwardIterator __temp = __parse_assertion(__first, __last); |
| 3751 | if (__temp == __first) |
| 3752 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3753 | __owns_one_state<_CharT>* __e = __end_; |
| 3754 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 3755 | __temp = __parse_atom(__first, __last); |
| 3756 | if (__temp != __first) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3757 | __first = __parse_ERE_dupl_symbol(__temp, __last, __e, |
| 3758 | __mexp_begin+1, __marked_count_+1); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 3759 | } |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3760 | else |
| 3761 | __first = __temp; |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 3762 | return __first; |
| 3763 | } |
| 3764 | |
| 3765 | template <class _CharT, class _Traits> |
| 3766 | template <class _ForwardIterator> |
| 3767 | _ForwardIterator |
| 3768 | basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first, |
| 3769 | _ForwardIterator __last) |
| 3770 | { |
| 3771 | if (__first != __last) |
| 3772 | { |
| 3773 | switch (*__first) |
| 3774 | { |
| 3775 | case '^': |
| 3776 | __push_l_anchor(); |
| 3777 | ++__first; |
| 3778 | break; |
| 3779 | case '$': |
| 3780 | __push_r_anchor(); |
| 3781 | ++__first; |
| 3782 | break; |
| 3783 | case '\\': |
| 3784 | { |
| 3785 | _ForwardIterator __temp = _STD::next(__first); |
| 3786 | if (__temp != __last) |
| 3787 | { |
| 3788 | if (*__temp == 'b') |
| 3789 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3790 | __push_word_boundary(false); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 3791 | __first = ++__temp; |
| 3792 | } |
| 3793 | else if (*__temp == 'B') |
| 3794 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3795 | __push_word_boundary(true); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 3796 | __first = ++__temp; |
| 3797 | } |
| 3798 | } |
| 3799 | } |
| 3800 | break; |
| 3801 | case '(': |
| 3802 | { |
| 3803 | _ForwardIterator __temp = _STD::next(__first); |
| 3804 | if (__temp != __last && *__temp == '?') |
| 3805 | { |
| 3806 | if (++__temp != __last) |
| 3807 | { |
| 3808 | switch (*__temp) |
| 3809 | { |
| 3810 | case '=': |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3811 | __push_lookahead(false); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 3812 | __temp = __parse_ecma_exp(++__temp, __last); |
| 3813 | if (__temp == __last || *__temp != ')') |
| 3814 | throw regex_error(regex_constants::error_paren); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 3815 | __first = ++__temp; |
| 3816 | break; |
| 3817 | case '!': |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3818 | __push_lookahead(true); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 3819 | __temp = __parse_ecma_exp(++__temp, __last); |
| 3820 | if (__temp == __last || *__temp != ')') |
| 3821 | throw regex_error(regex_constants::error_paren); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 3822 | __first = ++__temp; |
| 3823 | break; |
| 3824 | } |
| 3825 | } |
| 3826 | } |
| 3827 | } |
| 3828 | break; |
| 3829 | } |
| 3830 | } |
| 3831 | return __first; |
| 3832 | } |
| 3833 | |
| 3834 | template <class _CharT, class _Traits> |
| 3835 | template <class _ForwardIterator> |
| 3836 | _ForwardIterator |
| 3837 | basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first, |
| 3838 | _ForwardIterator __last) |
| 3839 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3840 | if (__first != __last) |
| 3841 | { |
| 3842 | switch (*__first) |
| 3843 | { |
| 3844 | case '.': |
| 3845 | __push_match_any_but_newline(); |
| 3846 | ++__first; |
| 3847 | break; |
| 3848 | case '\\': |
| 3849 | __first = __parse_atom_escape(__first, __last); |
| 3850 | break; |
| 3851 | case '[': |
| 3852 | __first = __parse_bracket_expression(__first, __last); |
| 3853 | break; |
| 3854 | case '(': |
| 3855 | { |
| 3856 | if (++__first == __last) |
| 3857 | throw regex_error(regex_constants::error_paren); |
| 3858 | _ForwardIterator __temp = _STD::next(__first); |
| 3859 | if (__temp != __last && *__first == '?' && *__temp == ':') |
| 3860 | { |
| 3861 | ++__open_count_; |
| 3862 | __first = __parse_ecma_exp(++__temp, __last); |
| 3863 | if (__first == __last || *__first != ')') |
| 3864 | throw regex_error(regex_constants::error_paren); |
| 3865 | --__open_count_; |
| 3866 | ++__first; |
| 3867 | } |
| 3868 | else |
| 3869 | { |
| 3870 | __push_begin_marked_subexpression(); |
| 3871 | unsigned __temp_count = __marked_count_; |
| 3872 | ++__open_count_; |
| 3873 | __first = __parse_ecma_exp(__first, __last); |
| 3874 | if (__first == __last || *__first != ')') |
| 3875 | throw regex_error(regex_constants::error_paren); |
| 3876 | __push_end_marked_subexpression(__temp_count); |
| 3877 | --__open_count_; |
| 3878 | ++__first; |
| 3879 | } |
| 3880 | } |
| 3881 | break; |
| 3882 | default: |
| 3883 | __first = __parse_pattern_character(__first, __last); |
| 3884 | break; |
| 3885 | } |
| 3886 | } |
| 3887 | return __first; |
| 3888 | } |
| 3889 | |
| 3890 | template <class _CharT, class _Traits> |
| 3891 | template <class _ForwardIterator> |
| 3892 | _ForwardIterator |
| 3893 | basic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first, |
| 3894 | _ForwardIterator __last) |
| 3895 | { |
| 3896 | if (__first != __last && *__first == '\\') |
| 3897 | { |
| 3898 | _ForwardIterator __t1 = _STD::next(__first); |
| 3899 | _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last); |
| 3900 | if (__t2 != __t1) |
| 3901 | __first = __t2; |
| 3902 | else |
| 3903 | { |
| 3904 | __t2 = __parse_character_class_escape(__t1, __last); |
| 3905 | if (__t2 != __t1) |
| 3906 | __first = __t2; |
| 3907 | else |
| 3908 | { |
| 3909 | __t2 = __parse_character_escape(__t1, __last); |
| 3910 | if (__t2 != __t1) |
| 3911 | __first = __t2; |
| 3912 | } |
| 3913 | } |
| 3914 | } |
| 3915 | return __first; |
| 3916 | } |
| 3917 | |
| 3918 | template <class _CharT, class _Traits> |
| 3919 | template <class _ForwardIterator> |
| 3920 | _ForwardIterator |
| 3921 | basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first, |
| 3922 | _ForwardIterator __last) |
| 3923 | { |
| 3924 | if (__first != __last) |
| 3925 | { |
| 3926 | if (*__first == '0') |
| 3927 | { |
| 3928 | __push_char(_CharT()); |
| 3929 | ++__first; |
| 3930 | } |
| 3931 | else if ('1' <= *__first && *__first <= '9') |
| 3932 | { |
| 3933 | unsigned __v = *__first - '0'; |
| 3934 | for (++__first; '0' <= *__first && *__first <= '9'; ++__first) |
| 3935 | __v = 10 * __v + *__first - '0'; |
| 3936 | if (__v > mark_count()) |
| 3937 | throw regex_error(regex_constants::error_backref); |
| 3938 | __push_back_ref(__v); |
| 3939 | } |
| 3940 | } |
| 3941 | return __first; |
| 3942 | } |
| 3943 | |
| 3944 | template <class _CharT, class _Traits> |
| 3945 | template <class _ForwardIterator> |
| 3946 | _ForwardIterator |
| 3947 | basic_regex<_CharT, _Traits>::__parse_character_class_escape(_ForwardIterator __first, |
| 3948 | _ForwardIterator __last) |
| 3949 | { |
| 3950 | if (__first != __last) |
| 3951 | { |
| 3952 | __bracket_expression<_CharT, _Traits>* __ml; |
| 3953 | switch (*__first) |
| 3954 | { |
| 3955 | case 'd': |
| 3956 | __ml = __start_matching_list(false); |
| 3957 | __ml->__add_class(ctype_base::digit); |
| 3958 | ++__first; |
| 3959 | break; |
| 3960 | case 'D': |
| 3961 | __ml = __start_matching_list(true); |
| 3962 | __ml->__add_class(ctype_base::digit); |
| 3963 | ++__first; |
| 3964 | break; |
| 3965 | case 's': |
| 3966 | __ml = __start_matching_list(false); |
| 3967 | __ml->__add_class(ctype_base::space); |
| 3968 | ++__first; |
| 3969 | break; |
| 3970 | case 'S': |
| 3971 | __ml = __start_matching_list(true); |
| 3972 | __ml->__add_class(ctype_base::space); |
| 3973 | ++__first; |
| 3974 | break; |
| 3975 | case 'w': |
| 3976 | __ml = __start_matching_list(false); |
| 3977 | __ml->__add_class(ctype_base::alnum); |
| 3978 | __ml->__add_char('_'); |
| 3979 | ++__first; |
| 3980 | break; |
| 3981 | case 'W': |
| 3982 | __ml = __start_matching_list(true); |
| 3983 | __ml->__add_class(ctype_base::alnum); |
| 3984 | __ml->__add_char('_'); |
| 3985 | ++__first; |
| 3986 | break; |
| 3987 | } |
| 3988 | } |
| 3989 | return __first; |
| 3990 | } |
| 3991 | |
| 3992 | template <class _CharT, class _Traits> |
| 3993 | template <class _ForwardIterator> |
| 3994 | _ForwardIterator |
| 3995 | basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first, |
| 3996 | _ForwardIterator __last) |
| 3997 | { |
| 3998 | if (__first != __last) |
| 3999 | { |
| 4000 | _ForwardIterator __t; |
| 4001 | unsigned __sum = 0; |
| 4002 | int __hd; |
| 4003 | switch (*__first) |
| 4004 | { |
| 4005 | case 'f': |
| 4006 | __push_char(_CharT(0xC)); |
| 4007 | ++__first; |
| 4008 | break; |
| 4009 | case 'n': |
| 4010 | __push_char(_CharT(0xA)); |
| 4011 | ++__first; |
| 4012 | break; |
| 4013 | case 'r': |
| 4014 | __push_char(_CharT(0xD)); |
| 4015 | ++__first; |
| 4016 | break; |
| 4017 | case 't': |
| 4018 | __push_char(_CharT(0x9)); |
| 4019 | ++__first; |
| 4020 | break; |
| 4021 | case 'v': |
| 4022 | __push_char(_CharT(0xB)); |
| 4023 | ++__first; |
| 4024 | break; |
| 4025 | case 'c': |
| 4026 | if ((__t = _STD::next(__first)) != __last) |
| 4027 | { |
| 4028 | if ('A' <= *__t <= 'Z' || 'a' <= *__t <= 'z') |
| 4029 | { |
| 4030 | __push_char(_CharT(*__t % 32)); |
| 4031 | __first = ++__t; |
| 4032 | } |
| 4033 | } |
| 4034 | break; |
| 4035 | case 'u': |
| 4036 | if (++__first == __last) |
| 4037 | throw regex_error(regex_constants::error_escape); |
| 4038 | __hd = __traits_.value(*__first, 16); |
| 4039 | if (__hd == -1) |
| 4040 | throw regex_error(regex_constants::error_escape); |
| 4041 | __sum = 16 * __sum + __hd; |
| 4042 | if (++__first == __last) |
| 4043 | throw regex_error(regex_constants::error_escape); |
| 4044 | __hd = __traits_.value(*__first, 16); |
| 4045 | if (__hd == -1) |
| 4046 | throw regex_error(regex_constants::error_escape); |
| 4047 | __sum = 16 * __sum + __hd; |
| 4048 | // drop through |
| 4049 | case 'x': |
| 4050 | if (++__first == __last) |
| 4051 | throw regex_error(regex_constants::error_escape); |
| 4052 | __hd = __traits_.value(*__first, 16); |
| 4053 | if (__hd == -1) |
| 4054 | throw regex_error(regex_constants::error_escape); |
| 4055 | __sum = 16 * __sum + __hd; |
| 4056 | if (++__first == __last) |
| 4057 | throw regex_error(regex_constants::error_escape); |
| 4058 | __hd = __traits_.value(*__first, 16); |
| 4059 | if (__hd == -1) |
| 4060 | throw regex_error(regex_constants::error_escape); |
| 4061 | __sum = 16 * __sum + __hd; |
| 4062 | __push_char(_CharT(__sum)); |
| 4063 | ++__first; |
| 4064 | break; |
| 4065 | default: |
| 4066 | if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum)) |
| 4067 | { |
| 4068 | __push_char(*__first); |
| 4069 | ++__first; |
| 4070 | } |
| 4071 | break; |
| 4072 | } |
| 4073 | } |
| 4074 | return __first; |
| 4075 | } |
| 4076 | |
| 4077 | template <class _CharT, class _Traits> |
| 4078 | template <class _ForwardIterator> |
| 4079 | _ForwardIterator |
| 4080 | basic_regex<_CharT, _Traits>::__parse_pattern_character(_ForwardIterator __first, |
| 4081 | _ForwardIterator __last) |
| 4082 | { |
| 4083 | if (__first != __last) |
| 4084 | { |
| 4085 | switch (*__first) |
| 4086 | { |
| 4087 | case '^': |
| 4088 | case '$': |
| 4089 | case '\\': |
| 4090 | case '.': |
| 4091 | case '*': |
| 4092 | case '+': |
| 4093 | case '?': |
| 4094 | case '(': |
| 4095 | case ')': |
| 4096 | case '[': |
| 4097 | case ']': |
| 4098 | case '{': |
| 4099 | case '}': |
| 4100 | case '|': |
| 4101 | break; |
| 4102 | default: |
| 4103 | __push_char(*__first); |
| 4104 | ++__first; |
| 4105 | break; |
| 4106 | } |
| 4107 | } |
| 4108 | return __first; |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4109 | } |
| 4110 | |
| 4111 | template <class _CharT, class _Traits> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4112 | void |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4113 | basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max, |
| 4114 | __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end, |
| 4115 | bool __greedy) |
| 4116 | { |
| 4117 | unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first())); |
| 4118 | __end_->first() = nullptr; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4119 | unique_ptr<__loop<_CharT> > __e2(new __loop<_CharT>(__loop_count_, |
| 4120 | __s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy, |
| 4121 | __min, __max)); |
| 4122 | __s->first() = nullptr; |
| 4123 | __e1.release(); |
| 4124 | __end_->first() = new __repeat_one_loop<_CharT>(__e2.get()); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4125 | __end_ = __e2->second(); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4126 | __s->first() = __e2.release(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4127 | ++__loop_count_; |
| 4128 | } |
| 4129 | |
| 4130 | template <class _CharT, class _Traits> |
| 4131 | void |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4132 | basic_regex<_CharT, _Traits>::__push_char(value_type __c) |
| 4133 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4134 | if (flags() & icase) |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4135 | __end_->first() = new __match_char_icase<_CharT, _Traits> |
| 4136 | (__traits_, __c, __end_->first()); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4137 | else if (flags() & collate) |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4138 | __end_->first() = new __match_char_collate<_CharT, _Traits> |
| 4139 | (__traits_, __c, __end_->first()); |
| 4140 | else |
| 4141 | __end_->first() = new __match_char<_CharT>(__c, __end_->first()); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 4142 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4143 | } |
| 4144 | |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4145 | template <class _CharT, class _Traits> |
| 4146 | void |
| 4147 | basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression() |
| 4148 | { |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 4149 | if (!(__flags_ & nosubs)) |
| 4150 | { |
| 4151 | __end_->first() = |
| 4152 | new __begin_marked_subexpression<_CharT>(++__marked_count_, |
| 4153 | __end_->first()); |
| 4154 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4155 | } |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4156 | } |
| 4157 | |
| 4158 | template <class _CharT, class _Traits> |
| 4159 | void |
| 4160 | basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub) |
| 4161 | { |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 4162 | if (!(__flags_ & nosubs)) |
| 4163 | { |
| 4164 | __end_->first() = |
| 4165 | new __end_marked_subexpression<_CharT>(__sub, __end_->first()); |
| 4166 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4167 | } |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4168 | } |
| 4169 | |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4170 | template <class _CharT, class _Traits> |
| 4171 | void |
| 4172 | basic_regex<_CharT, _Traits>::__push_r_anchor() |
| 4173 | { |
| 4174 | __end_->first() = new __r_anchor<_CharT>(__end_->first()); |
| 4175 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4176 | } |
| 4177 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4178 | template <class _CharT, class _Traits> |
| 4179 | void |
| 4180 | basic_regex<_CharT, _Traits>::__push_match_any() |
| 4181 | { |
| 4182 | __end_->first() = new __match_any<_CharT>(__end_->first()); |
| 4183 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4184 | } |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4185 | |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4186 | template <class _CharT, class _Traits> |
| 4187 | void |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4188 | basic_regex<_CharT, _Traits>::__push_match_any_but_newline() |
| 4189 | { |
| 4190 | __end_->first() = new __match_any_but_newline<_CharT>(__end_->first()); |
| 4191 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4192 | } |
| 4193 | |
| 4194 | template <class _CharT, class _Traits> |
| 4195 | void |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4196 | basic_regex<_CharT, _Traits>::__push_empty() |
| 4197 | { |
| 4198 | __end_->first() = new __empty_state<_CharT>(__end_->first()); |
| 4199 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4200 | } |
| 4201 | |
| 4202 | template <class _CharT, class _Traits> |
| 4203 | void |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4204 | basic_regex<_CharT, _Traits>::__push_word_boundary(bool __invert) |
| 4205 | { |
| 4206 | __end_->first() = new __word_boundary<_CharT, _Traits>(__traits_, __invert, |
| 4207 | __end_->first()); |
| 4208 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4209 | } |
| 4210 | |
| 4211 | template <class _CharT, class _Traits> |
| 4212 | void |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4213 | basic_regex<_CharT, _Traits>::__push_back_ref(int __i) |
| 4214 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4215 | if (flags() & icase) |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4216 | __end_->first() = new __back_ref_icase<_CharT, _Traits> |
| 4217 | (__traits_, __i, __end_->first()); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4218 | else if (flags() & collate) |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4219 | __end_->first() = new __back_ref_collate<_CharT, _Traits> |
| 4220 | (__traits_, __i, __end_->first()); |
| 4221 | else |
| 4222 | __end_->first() = new __back_ref<_CharT>(__i, __end_->first()); |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4223 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4224 | } |
| 4225 | |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4226 | template <class _CharT, class _Traits> |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 4227 | void |
| 4228 | basic_regex<_CharT, _Traits>::__push_alternation(__owns_one_state<_CharT>* __sa, |
| 4229 | __owns_one_state<_CharT>* __ea) |
| 4230 | { |
| 4231 | __sa->first() = new __alternate<_CharT>( |
| 4232 | static_cast<__owns_one_state<_CharT>*>(__sa->first()), |
| 4233 | static_cast<__owns_one_state<_CharT>*>(__ea->first())); |
| 4234 | __ea->first() = nullptr; |
| 4235 | __ea->first() = new __empty_state<_CharT>(__end_->first()); |
| 4236 | __end_->first() = nullptr; |
| 4237 | __end_->first() = new __empty_non_own_state<_CharT>(__ea->first()); |
| 4238 | __end_ = static_cast<__owns_one_state<_CharT>*>(__ea->first()); |
| 4239 | } |
| 4240 | |
| 4241 | template <class _CharT, class _Traits> |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4242 | __bracket_expression<_CharT, _Traits>* |
| 4243 | basic_regex<_CharT, _Traits>::__start_matching_list(bool __negate) |
| 4244 | { |
| 4245 | __bracket_expression<_CharT, _Traits>* __r = |
| 4246 | new __bracket_expression<_CharT, _Traits>(__traits_, __end_->first(), |
| 4247 | __negate, __flags_ & icase, |
| 4248 | __flags_ & collate); |
| 4249 | __end_->first() = __r; |
| 4250 | __end_ = __r; |
| 4251 | return __r; |
| 4252 | } |
| 4253 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 4254 | typedef basic_regex<char> regex; |
| 4255 | typedef basic_regex<wchar_t> wregex; |
| 4256 | |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4257 | // sub_match |
| 4258 | |
| 4259 | template <class _BidirectionalIterator> |
| 4260 | class sub_match |
| 4261 | : public pair<_BidirectionalIterator, _BidirectionalIterator> |
| 4262 | { |
| 4263 | public: |
| 4264 | typedef _BidirectionalIterator iterator; |
| 4265 | typedef typename iterator_traits<iterator>::value_type value_type; |
| 4266 | typedef typename iterator_traits<iterator>::difference_type difference_type; |
| 4267 | typedef basic_string<value_type> string_type; |
| 4268 | |
| 4269 | bool matched; |
| 4270 | |
| 4271 | difference_type length() const |
| 4272 | {return matched ? _STD::distance(this->first, this->second) : 0;} |
| 4273 | string_type str() const |
| 4274 | {return matched ? string_type(this->first, this->second) : string_type();} |
| 4275 | operator string_type() const |
| 4276 | {return str();} |
| 4277 | |
| 4278 | int compare(const sub_match& __s) const |
| 4279 | {return str().compare(__s.str());} |
| 4280 | int compare(const string_type& __s) const |
| 4281 | {return str().compare(__s);} |
| 4282 | int compare(const value_type* __s) const |
| 4283 | {return str().compare(__s);} |
| 4284 | }; |
| 4285 | |
| 4286 | typedef sub_match<const char*> csub_match; |
| 4287 | typedef sub_match<const wchar_t*> wcsub_match; |
| 4288 | typedef sub_match<string::const_iterator> ssub_match; |
| 4289 | typedef sub_match<wstring::const_iterator> wssub_match; |
| 4290 | |
| 4291 | template <class _BiIter> |
| 4292 | inline _LIBCPP_INLINE_VISIBILITY |
| 4293 | bool |
| 4294 | operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4295 | { |
| 4296 | return __x.compare(__y) == 0; |
| 4297 | } |
| 4298 | |
| 4299 | template <class _BiIter> |
| 4300 | inline _LIBCPP_INLINE_VISIBILITY |
| 4301 | bool |
| 4302 | operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4303 | { |
| 4304 | return !(__x == __y); |
| 4305 | } |
| 4306 | |
| 4307 | template <class _BiIter> |
| 4308 | inline _LIBCPP_INLINE_VISIBILITY |
| 4309 | bool |
| 4310 | operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4311 | { |
| 4312 | return __x.compare(__y) < 0; |
| 4313 | } |
| 4314 | |
| 4315 | template <class _BiIter> |
| 4316 | inline _LIBCPP_INLINE_VISIBILITY |
| 4317 | bool |
| 4318 | operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4319 | { |
| 4320 | return !(__y < __x); |
| 4321 | } |
| 4322 | |
| 4323 | template <class _BiIter> |
| 4324 | inline _LIBCPP_INLINE_VISIBILITY |
| 4325 | bool |
| 4326 | operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4327 | { |
| 4328 | return !(__x < __y); |
| 4329 | } |
| 4330 | |
| 4331 | template <class _BiIter> |
| 4332 | inline _LIBCPP_INLINE_VISIBILITY |
| 4333 | bool |
| 4334 | operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4335 | { |
| 4336 | return __y < __x; |
| 4337 | } |
| 4338 | |
| 4339 | template <class _BiIter, class _ST, class _SA> |
| 4340 | inline _LIBCPP_INLINE_VISIBILITY |
| 4341 | bool |
| 4342 | operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4343 | const sub_match<_BiIter>& __y) |
| 4344 | { |
| 4345 | return __y.compare(__x.c_str()) == 0; |
| 4346 | } |
| 4347 | |
| 4348 | template <class _BiIter, class _ST, class _SA> |
| 4349 | inline _LIBCPP_INLINE_VISIBILITY |
| 4350 | bool |
| 4351 | operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4352 | const sub_match<_BiIter>& __y) |
| 4353 | { |
| 4354 | return !(__x == __y); |
| 4355 | } |
| 4356 | |
| 4357 | template <class _BiIter, class _ST, class _SA> |
| 4358 | inline _LIBCPP_INLINE_VISIBILITY |
| 4359 | bool |
| 4360 | operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4361 | const sub_match<_BiIter>& __y) |
| 4362 | { |
| 4363 | return __y.compare(__x.c_str()) > 0; |
| 4364 | } |
| 4365 | |
| 4366 | template <class _BiIter, class _ST, class _SA> |
| 4367 | inline _LIBCPP_INLINE_VISIBILITY |
| 4368 | bool |
| 4369 | operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4370 | const sub_match<_BiIter>& __y) |
| 4371 | { |
| 4372 | return __y < __x; |
| 4373 | } |
| 4374 | |
| 4375 | template <class _BiIter, class _ST, class _SA> |
| 4376 | inline _LIBCPP_INLINE_VISIBILITY |
| 4377 | bool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4378 | const sub_match<_BiIter>& __y) |
| 4379 | { |
| 4380 | return !(__x < __y); |
| 4381 | } |
| 4382 | |
| 4383 | template <class _BiIter, class _ST, class _SA> |
| 4384 | inline _LIBCPP_INLINE_VISIBILITY |
| 4385 | bool |
| 4386 | operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4387 | const sub_match<_BiIter>& __y) |
| 4388 | { |
| 4389 | return !(__y < __x); |
| 4390 | } |
| 4391 | |
| 4392 | template <class _BiIter, class _ST, class _SA> |
| 4393 | inline _LIBCPP_INLINE_VISIBILITY |
| 4394 | bool |
| 4395 | operator==(const sub_match<_BiIter>& __x, |
| 4396 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4397 | { |
| 4398 | return __x.compare(__y.c_str()) == 0; |
| 4399 | } |
| 4400 | |
| 4401 | template <class _BiIter, class _ST, class _SA> |
| 4402 | inline _LIBCPP_INLINE_VISIBILITY |
| 4403 | bool |
| 4404 | operator!=(const sub_match<_BiIter>& __x, |
| 4405 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4406 | { |
| 4407 | return !(__x == __y); |
| 4408 | } |
| 4409 | |
| 4410 | template <class _BiIter, class _ST, class _SA> |
| 4411 | inline _LIBCPP_INLINE_VISIBILITY |
| 4412 | bool |
| 4413 | operator<(const sub_match<_BiIter>& __x, |
| 4414 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4415 | { |
| 4416 | return __x.compare(__y.c_str()) < 0; |
| 4417 | } |
| 4418 | |
| 4419 | template <class _BiIter, class _ST, class _SA> |
| 4420 | inline _LIBCPP_INLINE_VISIBILITY |
| 4421 | bool operator>(const sub_match<_BiIter>& __x, |
| 4422 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4423 | { |
| 4424 | return __y < __x; |
| 4425 | } |
| 4426 | |
| 4427 | template <class _BiIter, class _ST, class _SA> |
| 4428 | inline _LIBCPP_INLINE_VISIBILITY |
| 4429 | bool |
| 4430 | operator>=(const sub_match<_BiIter>& __x, |
| 4431 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4432 | { |
| 4433 | return !(__x < __y); |
| 4434 | } |
| 4435 | |
| 4436 | template <class _BiIter, class _ST, class _SA> |
| 4437 | inline _LIBCPP_INLINE_VISIBILITY |
| 4438 | bool |
| 4439 | operator<=(const sub_match<_BiIter>& __x, |
| 4440 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4441 | { |
| 4442 | return !(__y < __x); |
| 4443 | } |
| 4444 | |
| 4445 | template <class _BiIter> |
| 4446 | inline _LIBCPP_INLINE_VISIBILITY |
| 4447 | bool |
| 4448 | operator==(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4449 | const sub_match<_BiIter>& __y) |
| 4450 | { |
| 4451 | return __y.compare(__x) == 0; |
| 4452 | } |
| 4453 | |
| 4454 | template <class _BiIter> |
| 4455 | inline _LIBCPP_INLINE_VISIBILITY |
| 4456 | bool |
| 4457 | operator!=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4458 | const sub_match<_BiIter>& __y) |
| 4459 | { |
| 4460 | return !(__x == __y); |
| 4461 | } |
| 4462 | |
| 4463 | template <class _BiIter> |
| 4464 | inline _LIBCPP_INLINE_VISIBILITY |
| 4465 | bool |
| 4466 | operator<(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4467 | const sub_match<_BiIter>& __y) |
| 4468 | { |
| 4469 | return __y.compare(__x) > 0; |
| 4470 | } |
| 4471 | |
| 4472 | template <class _BiIter> |
| 4473 | inline _LIBCPP_INLINE_VISIBILITY |
| 4474 | bool |
| 4475 | operator>(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4476 | const sub_match<_BiIter>& __y) |
| 4477 | { |
| 4478 | return __y < __x; |
| 4479 | } |
| 4480 | |
| 4481 | template <class _BiIter> |
| 4482 | inline _LIBCPP_INLINE_VISIBILITY |
| 4483 | bool |
| 4484 | operator>=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4485 | const sub_match<_BiIter>& __y) |
| 4486 | { |
| 4487 | return !(__x < __y); |
| 4488 | } |
| 4489 | |
| 4490 | template <class _BiIter> |
| 4491 | inline _LIBCPP_INLINE_VISIBILITY |
| 4492 | bool |
| 4493 | operator<=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4494 | const sub_match<_BiIter>& __y) |
| 4495 | { |
| 4496 | return !(__y < __x); |
| 4497 | } |
| 4498 | |
| 4499 | template <class _BiIter> |
| 4500 | inline _LIBCPP_INLINE_VISIBILITY |
| 4501 | bool |
| 4502 | operator==(const sub_match<_BiIter>& __x, |
| 4503 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 4504 | { |
| 4505 | return __x.compare(__y) == 0; |
| 4506 | } |
| 4507 | |
| 4508 | template <class _BiIter> |
| 4509 | inline _LIBCPP_INLINE_VISIBILITY |
| 4510 | bool |
| 4511 | operator!=(const sub_match<_BiIter>& __x, |
| 4512 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 4513 | { |
| 4514 | return !(__x == __y); |
| 4515 | } |
| 4516 | |
| 4517 | template <class _BiIter> |
| 4518 | inline _LIBCPP_INLINE_VISIBILITY |
| 4519 | bool |
| 4520 | operator<(const sub_match<_BiIter>& __x, |
| 4521 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 4522 | { |
| 4523 | return __x.compare(__y) < 0; |
| 4524 | } |
| 4525 | |
| 4526 | template <class _BiIter> |
| 4527 | inline _LIBCPP_INLINE_VISIBILITY |
| 4528 | bool |
| 4529 | operator>(const sub_match<_BiIter>& __x, |
| 4530 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 4531 | { |
| 4532 | return __y < __x; |
| 4533 | } |
| 4534 | |
| 4535 | template <class _BiIter> |
| 4536 | inline _LIBCPP_INLINE_VISIBILITY |
| 4537 | bool |
| 4538 | operator>=(const sub_match<_BiIter>& __x, |
| 4539 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 4540 | { |
| 4541 | return !(__x < __y); |
| 4542 | } |
| 4543 | |
| 4544 | template <class _BiIter> |
| 4545 | inline _LIBCPP_INLINE_VISIBILITY |
| 4546 | bool |
| 4547 | operator<=(const sub_match<_BiIter>& __x, |
| 4548 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 4549 | { |
| 4550 | return !(__y < __x); |
| 4551 | } |
| 4552 | |
| 4553 | template <class _BiIter> |
| 4554 | inline _LIBCPP_INLINE_VISIBILITY |
| 4555 | bool |
| 4556 | operator==(typename iterator_traits<_BiIter>::value_type const& __x, |
| 4557 | const sub_match<_BiIter>& __y) |
| 4558 | { |
| 4559 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 4560 | return __y.compare(string_type(1, __x)) == 0; |
| 4561 | } |
| 4562 | |
| 4563 | template <class _BiIter> |
| 4564 | inline _LIBCPP_INLINE_VISIBILITY |
| 4565 | bool |
| 4566 | operator!=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 4567 | const sub_match<_BiIter>& __y) |
| 4568 | { |
| 4569 | return !(__x == __y); |
| 4570 | } |
| 4571 | |
| 4572 | template <class _BiIter> |
| 4573 | inline _LIBCPP_INLINE_VISIBILITY |
| 4574 | bool |
| 4575 | operator<(typename iterator_traits<_BiIter>::value_type const& __x, |
| 4576 | const sub_match<_BiIter>& __y) |
| 4577 | { |
| 4578 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 4579 | return __y.compare(string_type(1, __x)) > 0; |
| 4580 | } |
| 4581 | |
| 4582 | template <class _BiIter> |
| 4583 | inline _LIBCPP_INLINE_VISIBILITY |
| 4584 | bool |
| 4585 | operator>(typename iterator_traits<_BiIter>::value_type const& __x, |
| 4586 | const sub_match<_BiIter>& __y) |
| 4587 | { |
| 4588 | return __y < __x; |
| 4589 | } |
| 4590 | |
| 4591 | template <class _BiIter> |
| 4592 | inline _LIBCPP_INLINE_VISIBILITY |
| 4593 | bool |
| 4594 | operator>=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 4595 | const sub_match<_BiIter>& __y) |
| 4596 | { |
| 4597 | return !(__x < __y); |
| 4598 | } |
| 4599 | |
| 4600 | template <class _BiIter> |
| 4601 | inline _LIBCPP_INLINE_VISIBILITY |
| 4602 | bool |
| 4603 | operator<=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 4604 | const sub_match<_BiIter>& __y) |
| 4605 | { |
| 4606 | return !(__y < __x); |
| 4607 | } |
| 4608 | |
| 4609 | template <class _BiIter> |
| 4610 | inline _LIBCPP_INLINE_VISIBILITY |
| 4611 | bool |
| 4612 | operator==(const sub_match<_BiIter>& __x, |
| 4613 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 4614 | { |
| 4615 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 4616 | return __x.compare(string_type(1, __y)) == 0; |
| 4617 | } |
| 4618 | |
| 4619 | template <class _BiIter> |
| 4620 | inline _LIBCPP_INLINE_VISIBILITY |
| 4621 | bool |
| 4622 | operator!=(const sub_match<_BiIter>& __x, |
| 4623 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 4624 | { |
| 4625 | return !(__x == __y); |
| 4626 | } |
| 4627 | |
| 4628 | template <class _BiIter> |
| 4629 | inline _LIBCPP_INLINE_VISIBILITY |
| 4630 | bool |
| 4631 | operator<(const sub_match<_BiIter>& __x, |
| 4632 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 4633 | { |
| 4634 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 4635 | return __x.compare(string_type(1, __y)) < 0; |
| 4636 | } |
| 4637 | |
| 4638 | template <class _BiIter> |
| 4639 | inline _LIBCPP_INLINE_VISIBILITY |
| 4640 | bool |
| 4641 | operator>(const sub_match<_BiIter>& __x, |
| 4642 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 4643 | { |
| 4644 | return __y < __x; |
| 4645 | } |
| 4646 | |
| 4647 | template <class _BiIter> |
| 4648 | inline _LIBCPP_INLINE_VISIBILITY |
| 4649 | bool |
| 4650 | operator>=(const sub_match<_BiIter>& __x, |
| 4651 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 4652 | { |
| 4653 | return !(__x < __y); |
| 4654 | } |
| 4655 | |
| 4656 | template <class _BiIter> |
| 4657 | inline _LIBCPP_INLINE_VISIBILITY |
| 4658 | bool |
| 4659 | operator<=(const sub_match<_BiIter>& __x, |
| 4660 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 4661 | { |
| 4662 | return !(__y < __x); |
| 4663 | } |
| 4664 | |
| 4665 | template <class _CharT, class _ST, class _BiIter> |
| 4666 | inline _LIBCPP_INLINE_VISIBILITY |
| 4667 | basic_ostream<_CharT, _ST>& |
| 4668 | operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m) |
| 4669 | { |
| 4670 | return __os << __m.str(); |
| 4671 | } |
| 4672 | |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4673 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 4674 | class match_results |
| 4675 | { |
| 4676 | public: |
| 4677 | typedef _Allocator allocator_type; |
| 4678 | typedef sub_match<_BidirectionalIterator> value_type; |
| 4679 | private: |
| 4680 | typedef vector<value_type, allocator_type> __container_type; |
| 4681 | |
| 4682 | __container_type __matches_; |
| 4683 | value_type __unmatched_; |
| 4684 | value_type __prefix_; |
| 4685 | value_type __suffix_; |
| 4686 | public: |
| 4687 | typedef const value_type& const_reference; |
| 4688 | typedef const_reference reference; |
| 4689 | typedef typename __container_type::const_iterator const_iterator; |
| 4690 | typedef const_iterator iterator; |
| 4691 | typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; |
| 4692 | typedef typename allocator_traits<allocator_type>::size_type size_type; |
| 4693 | typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type; |
| 4694 | typedef basic_string<char_type> string_type; |
| 4695 | |
| 4696 | // construct/copy/destroy: |
| 4697 | explicit match_results(const allocator_type& __a = allocator_type()); |
| 4698 | // match_results(const match_results&) = default; |
| 4699 | // match_results& operator=(const match_results&) = default; |
| 4700 | #ifdef _LIBCPP_MOVE |
| 4701 | // match_results(match_results&& __m) = default; |
| 4702 | // match_results& operator=(match_results&& __m) = default; |
| 4703 | #endif |
| 4704 | // ~match_results() = default; |
| 4705 | |
| 4706 | // size: |
| 4707 | size_type size() const {return __matches_.size();} |
| 4708 | size_type max_size() const {return __matches_.max_size();} |
| 4709 | bool empty() const {return size() == 0;} |
| 4710 | |
| 4711 | // element access: |
| 4712 | difference_type length(size_type __sub = 0) const |
| 4713 | {return (*this)[__sub].length();} |
| 4714 | difference_type position(size_type __sub = 0) const |
| 4715 | {return _STD::distance(__prefix_.first, (*this)[__sub].first);} |
| 4716 | string_type str(size_type __sub = 0) const |
| 4717 | {return (*this)[__sub].str();} |
| 4718 | const_reference operator[](size_type __n) const |
| 4719 | {return __n < __matches_.size() ? __matches_[__n] : __unmatched_;} |
| 4720 | |
| 4721 | const_reference prefix() const {return __prefix_;} |
| 4722 | const_reference suffix() const {return __suffix_;} |
| 4723 | |
| 4724 | const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin() + 1;} |
| 4725 | const_iterator end() const {return __matches_.end();} |
| 4726 | const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin() + 1;} |
| 4727 | const_iterator cend() const {return __matches_.end();} |
| 4728 | |
| 4729 | // format: |
| 4730 | template <class _OutputIter> |
| 4731 | _OutputIter |
| 4732 | format(_OutputIter __out, const char_type* __fmt_first, |
| 4733 | const char_type* __fmt_last, |
| 4734 | regex_constants::match_flag_type __flags = regex_constants::format_default) const; |
| 4735 | template <class _OutputIter, class _ST, class _SA> |
| 4736 | _OutputIter |
| 4737 | format(_OutputIter __out, const basic_string<char_type, _ST, _SA>& __fmt, |
| 4738 | regex_constants::match_flag_type __flags = regex_constants::format_default) const; |
| 4739 | template <class _ST, class _SA> |
| 4740 | basic_string<char_type, _ST, _SA> |
| 4741 | format(const basic_string<char_type, _ST, _SA>& __fmt, |
| 4742 | regex_constants::match_flag_type __flags = regex_constants::format_default) const; |
| 4743 | string_type |
| 4744 | format(const char_type* __fmt, |
| 4745 | regex_constants::match_flag_type __flags = regex_constants::format_default) const; |
| 4746 | |
| 4747 | // allocator: |
| 4748 | allocator_type get_allocator() const {return __matches_.get_allocator();} |
| 4749 | |
| 4750 | // swap: |
| 4751 | void swap(match_results& __m); |
| 4752 | |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 4753 | template <class _B, class _A> |
| 4754 | void __assign(_BidirectionalIterator __f, _BidirectionalIterator __l, |
| 4755 | const match_results<_B, _A>& __m) |
| 4756 | { |
| 4757 | _B __mf = __m.prefix().first; |
| 4758 | __matches_.resize(__m.size()); |
| 4759 | for (size_type __i = 0; __i < __matches_.size(); ++__i) |
| 4760 | { |
| 4761 | __matches_[__i].first = next(__f, _STD::distance(__mf, __m[__i].first)); |
| 4762 | __matches_[__i].second = next(__f, _STD::distance(__mf, __m[__i].second)); |
| 4763 | __matches_[__i].matched = __m[__i].matched; |
| 4764 | } |
| 4765 | __unmatched_.first = __l; |
| 4766 | __unmatched_.second = __l; |
| 4767 | __unmatched_.matched = false; |
| 4768 | __prefix_.first = next(__f, _STD::distance(__mf, __m.prefix().first)); |
| 4769 | __prefix_.second = next(__f, _STD::distance(__mf, __m.prefix().second)); |
| 4770 | __prefix_.matched = __m.prefix().matched; |
| 4771 | __suffix_.first = next(__f, _STD::distance(__mf, __m.suffix().first)); |
| 4772 | __suffix_.second = next(__f, _STD::distance(__mf, __m.suffix().second)); |
| 4773 | __suffix_.matched = __m.suffix().matched; |
| 4774 | } |
| 4775 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 4776 | private: |
| 4777 | void __init(unsigned __s, |
| 4778 | _BidirectionalIterator __f, _BidirectionalIterator __l); |
| 4779 | |
| 4780 | template <class, class> friend class basic_regex; |
| 4781 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 4782 | template <class _B, class _A, class _C, class _T> |
| 4783 | friend |
| 4784 | bool |
| 4785 | regex_match(_B, _B, match_results<_B, _A>&, const basic_regex<_C, _T>&, |
| 4786 | regex_constants::match_flag_type); |
| 4787 | }; |
| 4788 | |
| 4789 | template <class _BidirectionalIterator, class _Allocator> |
| 4790 | match_results<_BidirectionalIterator, _Allocator>::match_results( |
| 4791 | const allocator_type& __a) |
| 4792 | : __matches_(__a), |
| 4793 | __unmatched_(), |
| 4794 | __prefix_(), |
| 4795 | __suffix_() |
| 4796 | { |
| 4797 | } |
| 4798 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 4799 | template <class _BidirectionalIterator, class _Allocator> |
| 4800 | void |
| 4801 | match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s, |
| 4802 | _BidirectionalIterator __f, _BidirectionalIterator __l) |
| 4803 | { |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 4804 | __unmatched_.first = __l; |
| 4805 | __unmatched_.second = __l; |
| 4806 | __unmatched_.matched = false; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4807 | __matches_.assign(__s, __unmatched_); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 4808 | __prefix_.first = __f; |
| 4809 | __prefix_.second = __f; |
| 4810 | __prefix_.matched = false; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 4811 | __suffix_ = __unmatched_; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 4812 | } |
| 4813 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 4814 | typedef match_results<const char*> cmatch; |
| 4815 | typedef match_results<const wchar_t*> wcmatch; |
| 4816 | typedef match_results<string::const_iterator> smatch; |
| 4817 | typedef match_results<wstring::const_iterator> wsmatch; |
| 4818 | |
| 4819 | template <class _BidirectionalIterator, class _Allocator> |
| 4820 | bool |
| 4821 | operator==(const match_results<_BidirectionalIterator, _Allocator>& __x, |
| 4822 | const match_results<_BidirectionalIterator, _Allocator>& __y); |
| 4823 | |
| 4824 | template <class _BidirectionalIterator, class _Allocator> |
| 4825 | bool |
| 4826 | operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x, |
| 4827 | const match_results<_BidirectionalIterator, _Allocator>& __y); |
| 4828 | |
| 4829 | template <class _BidirectionalIterator, class _Allocator> |
| 4830 | void |
| 4831 | swap(match_results<_BidirectionalIterator, _Allocator>& __x, |
| 4832 | match_results<_BidirectionalIterator, _Allocator>& __y); |
| 4833 | |
| 4834 | // regex_search |
| 4835 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 4836 | template <class _CharT, class _Traits> |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4837 | template <class _Allocator> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 4838 | bool |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4839 | basic_regex<_CharT, _Traits>::__match_at_start_ecma( |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4840 | const _CharT* __first, const _CharT* __last, |
| 4841 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4842 | regex_constants::match_flag_type __flags) const |
| 4843 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4844 | vector<__state> __states; |
| 4845 | ptrdiff_t __j = 0; |
| 4846 | ptrdiff_t _N = _STD::distance(__first, __last); |
| 4847 | __node* __st = __start_.get(); |
| 4848 | if (__st) |
| 4849 | { |
| 4850 | __states.push_back(__state()); |
| 4851 | __states.back().__do_ = 0; |
| 4852 | __states.back().__first_ = __first; |
| 4853 | __states.back().__current_ = __first; |
| 4854 | __states.back().__last_ = __last; |
| 4855 | __states.back().__sub_matches_.resize(mark_count()); |
| 4856 | __states.back().__loop_data_.resize(__loop_count()); |
| 4857 | __states.back().__node_ = __st; |
| 4858 | __states.back().__flags_ = __flags; |
| 4859 | bool __matched = false; |
| 4860 | do |
| 4861 | { |
| 4862 | __state& __s = __states.back(); |
| 4863 | if (__s.__node_) |
| 4864 | __s.__node_->__exec(__s); |
| 4865 | switch (__s.__do_) |
| 4866 | { |
| 4867 | case __state::__end_state: |
| 4868 | __m.__matches_[0].first = __first; |
| 4869 | __m.__matches_[0].second = _STD::next(__first, __s.__current_ - __first); |
| 4870 | __m.__matches_[0].matched = true; |
| 4871 | for (unsigned __i = 0; __i < __s.__sub_matches_.size(); ++__i) |
| 4872 | __m.__matches_[__i+1] = __s.__sub_matches_[__i]; |
| 4873 | return true; |
| 4874 | case __state::__accept_and_consume: |
| 4875 | case __state::__repeat: |
| 4876 | case __state::__accept_but_not_consume: |
| 4877 | break; |
| 4878 | case __state::__split: |
| 4879 | { |
| 4880 | __state __snext = __s; |
| 4881 | __s.__node_->__exec_split(true, __s); |
| 4882 | __snext.__node_->__exec_split(false, __snext); |
| 4883 | __states.push_back(_STD::move(__snext)); |
| 4884 | } |
| 4885 | break; |
| 4886 | case __state::__reject: |
| 4887 | __states.pop_back(); |
| 4888 | break; |
| 4889 | default: |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame^] | 4890 | throw regex_error(regex_constants::__re_err_unknown); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4891 | break; |
| 4892 | } |
| 4893 | } while (!__states.empty()); |
| 4894 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4895 | return false; |
| 4896 | } |
| 4897 | |
| 4898 | template <class _CharT, class _Traits> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 4899 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4900 | bool |
| 4901 | basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs( |
| 4902 | const _CharT* __first, const _CharT* __last, |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 4903 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4904 | regex_constants::match_flag_type __flags) const |
| 4905 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4906 | deque<__state> __states; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 4907 | ptrdiff_t __highest_j = 0; |
| 4908 | ptrdiff_t _N = _STD::distance(__first, __last); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4909 | __node* __st = __start_.get(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4910 | if (__st) |
| 4911 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4912 | __states.push_back(__state()); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4913 | __states.back().__do_ = 0; |
| 4914 | __states.back().__first_ = __first; |
| 4915 | __states.back().__current_ = __first; |
| 4916 | __states.back().__last_ = __last; |
| 4917 | __states.back().__loop_data_.resize(__loop_count()); |
| 4918 | __states.back().__node_ = __st; |
| 4919 | __states.back().__flags_ = __flags; |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 4920 | bool __matched = false; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4921 | do |
| 4922 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4923 | __state& __s = __states.back(); |
| 4924 | if (__s.__node_) |
| 4925 | __s.__node_->__exec(__s); |
| 4926 | switch (__s.__do_) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4927 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4928 | case __state::__end_state: |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame^] | 4929 | if (!__matched || __highest_j < __s.__current_ - __s.__first_) |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 4930 | __highest_j = __s.__current_ - __s.__first_; |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame^] | 4931 | __matched = true; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4932 | if (__highest_j == _N) |
| 4933 | __states.clear(); |
| 4934 | else |
| 4935 | __states.pop_back(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4936 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4937 | case __state::__consume_input: |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4938 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4939 | case __state::__accept_and_consume: |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4940 | __states.push_front(_STD::move(__s)); |
| 4941 | __states.pop_back(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4942 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4943 | case __state::__repeat: |
| 4944 | case __state::__accept_but_not_consume: |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4945 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4946 | case __state::__split: |
| 4947 | { |
| 4948 | __state __snext = __s; |
| 4949 | __s.__node_->__exec_split(true, __s); |
| 4950 | __snext.__node_->__exec_split(false, __snext); |
| 4951 | __states.push_back(_STD::move(__snext)); |
| 4952 | } |
| 4953 | break; |
| 4954 | case __state::__reject: |
| 4955 | __states.pop_back(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4956 | break; |
| 4957 | default: |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame^] | 4958 | throw regex_error(regex_constants::__re_err_unknown); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4959 | break; |
| 4960 | } |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4961 | } while (!__states.empty()); |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 4962 | if (__matched) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4963 | { |
| 4964 | __m.__matches_[0].first = __first; |
| 4965 | __m.__matches_[0].second = _STD::next(__first, __highest_j); |
| 4966 | __m.__matches_[0].matched = true; |
| 4967 | return true; |
| 4968 | } |
| 4969 | } |
| 4970 | return false; |
| 4971 | } |
| 4972 | |
| 4973 | template <class _CharT, class _Traits> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 4974 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4975 | bool |
| 4976 | basic_regex<_CharT, _Traits>::__match_at_start_posix_subs( |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 4977 | const _CharT* __first, const _CharT* __last, |
| 4978 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4979 | regex_constants::match_flag_type __flags) const |
| 4980 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4981 | vector<__state> __states; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4982 | __state __best_state; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 4983 | ptrdiff_t __j = 0; |
| 4984 | ptrdiff_t __highest_j = 0; |
| 4985 | ptrdiff_t _N = _STD::distance(__first, __last); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4986 | __node* __st = __start_.get(); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 4987 | if (__st) |
| 4988 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4989 | __states.push_back(__state()); |
| 4990 | __states.back().__do_ = 0; |
| 4991 | __states.back().__first_ = __first; |
| 4992 | __states.back().__current_ = __first; |
| 4993 | __states.back().__last_ = __last; |
| 4994 | __states.back().__sub_matches_.resize(mark_count()); |
| 4995 | __states.back().__loop_data_.resize(__loop_count()); |
| 4996 | __states.back().__node_ = __st; |
| 4997 | __states.back().__flags_ = __flags; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 4998 | const _CharT* __current = __first; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4999 | bool __matched = false; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5000 | do |
| 5001 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5002 | __state& __s = __states.back(); |
| 5003 | if (__s.__node_) |
| 5004 | __s.__node_->__exec(__s); |
| 5005 | switch (__s.__do_) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5006 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5007 | case __state::__end_state: |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame^] | 5008 | if (!__matched || __highest_j < __s.__current_ - __s.__first_) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5009 | { |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame^] | 5010 | __highest_j = __s.__current_ - __s.__first_; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5011 | __best_state = __s; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5012 | } |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame^] | 5013 | __matched = true; |
| 5014 | if (__highest_j == _N) |
| 5015 | __states.clear(); |
| 5016 | else |
| 5017 | __states.pop_back(); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5018 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5019 | case __state::__accept_and_consume: |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 5020 | __j += __s.__current_ - __current; |
| 5021 | __current = __s.__current_; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5022 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5023 | case __state::__repeat: |
| 5024 | case __state::__accept_but_not_consume: |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5025 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5026 | case __state::__split: |
| 5027 | { |
| 5028 | __state __snext = __s; |
| 5029 | __s.__node_->__exec_split(true, __s); |
| 5030 | __snext.__node_->__exec_split(false, __snext); |
| 5031 | __states.push_back(_STD::move(__snext)); |
| 5032 | } |
| 5033 | break; |
| 5034 | case __state::__reject: |
| 5035 | __states.pop_back(); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5036 | break; |
| 5037 | default: |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame^] | 5038 | throw regex_error(regex_constants::__re_err_unknown); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5039 | break; |
| 5040 | } |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5041 | } while (!__states.empty()); |
| 5042 | if (__matched) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5043 | { |
| 5044 | __m.__matches_[0].first = __first; |
| 5045 | __m.__matches_[0].second = _STD::next(__first, __highest_j); |
| 5046 | __m.__matches_[0].matched = true; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5047 | for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i) |
| 5048 | __m.__matches_[__i+1] = __best_state.__sub_matches_[__i]; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5049 | return true; |
| 5050 | } |
| 5051 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5052 | return false; |
| 5053 | } |
| 5054 | |
| 5055 | template <class _CharT, class _Traits> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5056 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5057 | bool |
| 5058 | basic_regex<_CharT, _Traits>::__match_at_start( |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5059 | const _CharT* __first, const _CharT* __last, |
| 5060 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5061 | regex_constants::match_flag_type __flags) const |
| 5062 | { |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame^] | 5063 | if ((__flags_ & 0x1F0) == ECMAScript) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5064 | return __match_at_start_ecma(__first, __last, __m, __flags); |
| 5065 | if (mark_count() == 0) |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame^] | 5066 | return __match_at_start_posix_nosubs(__first, __last, __m, __flags); |
| 5067 | return __match_at_start_posix_subs(__first, __last, __m, __flags); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5068 | } |
| 5069 | |
| 5070 | template <class _CharT, class _Traits> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5071 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5072 | bool |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5073 | basic_regex<_CharT, _Traits>::__search( |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5074 | const _CharT* __first, const _CharT* __last, |
| 5075 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5076 | regex_constants::match_flag_type __flags) const |
| 5077 | { |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 5078 | if (__left_anchor_) |
| 5079 | __flags |= regex_constants::match_continuous; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5080 | __m.__init(1 + mark_count(), __first, __last); |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame^] | 5081 | if (__match_at_start(__first, __last, __m, __flags)) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5082 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5083 | __m.__prefix_.second = __m[0].first; |
| 5084 | __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; |
| 5085 | __m.__suffix_.first = __m[0].second; |
| 5086 | __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; |
| 5087 | return true; |
| 5088 | } |
| 5089 | if (!(__flags & regex_constants::match_continuous)) |
| 5090 | { |
| 5091 | __m.__matches_.assign(__m.size(), __m.__unmatched_); |
| 5092 | for (++__first; __first != __last; ++__first) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5093 | { |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame^] | 5094 | if (__match_at_start(__first, __last, __m, __flags)) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5095 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5096 | __m.__prefix_.second = __m[0].first; |
| 5097 | __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; |
| 5098 | __m.__suffix_.first = __m[0].second; |
| 5099 | __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; |
| 5100 | return true; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5101 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5102 | __m.__matches_.assign(__m.size(), __m.__unmatched_); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5103 | } |
| 5104 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5105 | __m.__matches_.clear(); |
| 5106 | return false; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5107 | } |
| 5108 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5109 | template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5110 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5111 | bool |
| 5112 | regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 5113 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 5114 | const basic_regex<_CharT, _Traits>& __e, |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5115 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5116 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5117 | basic_string<_CharT> __s(__first, __last); |
| 5118 | match_results<const _CharT*> __mc; |
| 5119 | bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
| 5120 | __m.__assign(__first, __last, __mc); |
| 5121 | return __r; |
| 5122 | } |
| 5123 | |
| 5124 | template <class _Allocator, class _CharT, class _Traits> |
| 5125 | inline _LIBCPP_INLINE_VISIBILITY |
| 5126 | bool |
| 5127 | regex_search(const _CharT* __first, const _CharT* __last, |
| 5128 | match_results<const _CharT*, _Allocator>& __m, |
| 5129 | const basic_regex<_CharT, _Traits>& __e, |
| 5130 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5131 | { |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5132 | return __e.__search(__first, __last, __m, __flags); |
| 5133 | } |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5134 | |
| 5135 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 5136 | inline _LIBCPP_INLINE_VISIBILITY |
| 5137 | bool |
| 5138 | regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 5139 | const basic_regex<_CharT, _Traits>& __e, |
| 5140 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5141 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5142 | basic_string<_CharT> __s(__first, __last); |
| 5143 | match_results<const _CharT*> __mc; |
| 5144 | return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
| 5145 | } |
| 5146 | |
| 5147 | template <class _CharT, class _Traits> |
| 5148 | inline _LIBCPP_INLINE_VISIBILITY |
| 5149 | bool |
| 5150 | regex_search(const _CharT* __first, const _CharT* __last, |
| 5151 | const basic_regex<_CharT, _Traits>& __e, |
| 5152 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5153 | { |
| 5154 | match_results<const _CharT*> __mc; |
| 5155 | return __e.__search(__first, __last, __mc, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5156 | } |
| 5157 | |
| 5158 | template <class _CharT, class _Allocator, class _Traits> |
| 5159 | inline _LIBCPP_INLINE_VISIBILITY |
| 5160 | bool |
| 5161 | regex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, |
| 5162 | const basic_regex<_CharT, _Traits>& __e, |
| 5163 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5164 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5165 | return __e.__search(__str, __str + _Traits::length(__str), __m, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5166 | } |
| 5167 | |
| 5168 | template <class _CharT, class _Traits> |
| 5169 | inline _LIBCPP_INLINE_VISIBILITY |
| 5170 | bool |
| 5171 | regex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, |
| 5172 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5173 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5174 | match_results<const _CharT*> __m; |
| 5175 | return _STD::regex_search(__str, __m, __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5176 | } |
| 5177 | |
| 5178 | template <class _ST, class _SA, class _CharT, class _Traits> |
| 5179 | inline _LIBCPP_INLINE_VISIBILITY |
| 5180 | bool |
| 5181 | regex_search(const basic_string<_CharT, _ST, _SA>& __s, |
| 5182 | const basic_regex<_CharT, _Traits>& __e, |
| 5183 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5184 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5185 | match_results<const _CharT*> __mc; |
| 5186 | return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5187 | } |
| 5188 | |
| 5189 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 5190 | inline _LIBCPP_INLINE_VISIBILITY |
| 5191 | bool |
| 5192 | regex_search(const basic_string<_CharT, _ST, _SA>& __s, |
| 5193 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 5194 | const basic_regex<_CharT, _Traits>& __e, |
| 5195 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5196 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5197 | match_results<const _CharT*> __mc; |
| 5198 | bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
| 5199 | __m.__assign(__s.begin(), __s.end(), __mc); |
| 5200 | return __r; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5201 | } |
| 5202 | |
| 5203 | // regex_match |
| 5204 | |
| 5205 | template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> |
| 5206 | bool |
| 5207 | regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 5208 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 5209 | const basic_regex<_CharT, _Traits>& __e, |
| 5210 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5211 | { |
| 5212 | bool __r = _STD::regex_search(__first, __last, __m, __e, |
| 5213 | __flags | regex_constants::match_continuous); |
| 5214 | if (__r) |
| 5215 | { |
| 5216 | __r = !__m.suffix().matched; |
| 5217 | if (!__r) |
| 5218 | __m.__matches_.clear(); |
| 5219 | } |
| 5220 | return __r; |
| 5221 | } |
| 5222 | |
| 5223 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 5224 | inline _LIBCPP_INLINE_VISIBILITY |
| 5225 | bool |
| 5226 | regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 5227 | const basic_regex<_CharT, _Traits>& __e, |
| 5228 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5229 | { |
| 5230 | match_results<_BidirectionalIterator> __m; |
| 5231 | return _STD::regex_match(__first, __last, __m, __e, __flags); |
| 5232 | } |
| 5233 | |
| 5234 | template <class _CharT, class _Allocator, class _Traits> |
| 5235 | inline _LIBCPP_INLINE_VISIBILITY |
| 5236 | bool |
| 5237 | regex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, |
| 5238 | const basic_regex<_CharT, _Traits>& __e, |
| 5239 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5240 | { |
| 5241 | return _STD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags); |
| 5242 | } |
| 5243 | |
| 5244 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 5245 | inline _LIBCPP_INLINE_VISIBILITY |
| 5246 | bool |
| 5247 | regex_match(const basic_string<_CharT, _ST, _SA>& __s, |
| 5248 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 5249 | const basic_regex<_CharT, _Traits>& __e, |
| 5250 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5251 | { |
| 5252 | return _STD::regex_match(__s.begin(), __s.end(), __m, __e, __flags); |
| 5253 | } |
| 5254 | |
| 5255 | template <class _CharT, class _Traits> |
| 5256 | inline _LIBCPP_INLINE_VISIBILITY |
| 5257 | bool |
| 5258 | regex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, |
| 5259 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5260 | { |
| 5261 | return _STD::regex_match(__str, __str + _Traits::length(__str), __e, __flags); |
| 5262 | } |
| 5263 | |
| 5264 | template <class _ST, class _SA, class _CharT, class _Traits> |
| 5265 | inline _LIBCPP_INLINE_VISIBILITY |
| 5266 | bool |
| 5267 | regex_match(const basic_string<_CharT, _ST, _SA>& __s, |
| 5268 | const basic_regex<_CharT, _Traits>& __e, |
| 5269 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5270 | { |
| 5271 | return _STD::regex_match(__s.begin(), __s.end(), __e, __flags); |
| 5272 | } |
| 5273 | |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 5274 | _LIBCPP_END_NAMESPACE_STD |
| 5275 | |
| 5276 | #endif // _LIBCPP_REGEX |