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