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