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 | { |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame^] | 3426 | unsigned __grammar = __flags_ & 0x1F0; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3427 | switch (*__first) |
| 3428 | { |
| 3429 | case '*': |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3430 | ++__first; |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame^] | 3431 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3432 | { |
| 3433 | ++__first; |
| 3434 | __push_nongreedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
| 3435 | } |
| 3436 | else |
| 3437 | __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3438 | break; |
| 3439 | case '+': |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3440 | ++__first; |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame^] | 3441 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3442 | { |
| 3443 | ++__first; |
| 3444 | __push_nongreedy_inf_repeat(1, __s, __mexp_begin, __mexp_end); |
| 3445 | } |
| 3446 | else |
| 3447 | __push_greedy_inf_repeat(1, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3448 | break; |
| 3449 | case '?': |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3450 | ++__first; |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame^] | 3451 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3452 | { |
| 3453 | ++__first; |
| 3454 | __push_loop(0, 1, __s, __mexp_begin, __mexp_end, false); |
| 3455 | } |
| 3456 | else |
| 3457 | __push_loop(0, 1, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3458 | break; |
| 3459 | case '{': |
| 3460 | { |
| 3461 | int __min; |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3462 | _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3463 | if (__temp == __first) |
| 3464 | throw regex_error(regex_constants::error_badbrace); |
| 3465 | __first = __temp; |
| 3466 | if (__first == __last) |
| 3467 | throw regex_error(regex_constants::error_brace); |
| 3468 | switch (*__first) |
| 3469 | { |
| 3470 | case '}': |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3471 | ++__first; |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame^] | 3472 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3473 | { |
| 3474 | ++__first; |
| 3475 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, false); |
| 3476 | } |
| 3477 | else |
| 3478 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3479 | break; |
| 3480 | case ',': |
| 3481 | if (++__first == __last) |
| 3482 | throw regex_error(regex_constants::error_badbrace); |
| 3483 | if (*__first == '}') |
| 3484 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3485 | ++__first; |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame^] | 3486 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3487 | { |
| 3488 | ++__first; |
| 3489 | __push_nongreedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
| 3490 | } |
| 3491 | else |
| 3492 | __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3493 | } |
| 3494 | else |
| 3495 | { |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3496 | int __max = -1; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3497 | __temp = __parse_DUP_COUNT(__first, __last, __max); |
| 3498 | if (__temp == __first) |
| 3499 | throw regex_error(regex_constants::error_brace); |
| 3500 | __first = __temp; |
| 3501 | if (__first == __last || *__first != '}') |
| 3502 | throw regex_error(regex_constants::error_brace); |
| 3503 | ++__first; |
| 3504 | if (__max < __min) |
| 3505 | throw regex_error(regex_constants::error_badbrace); |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame^] | 3506 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3507 | { |
| 3508 | ++__first; |
| 3509 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, false); |
| 3510 | } |
| 3511 | else |
| 3512 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3513 | } |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3514 | break; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3515 | default: |
| 3516 | throw regex_error(regex_constants::error_badbrace); |
| 3517 | } |
| 3518 | } |
| 3519 | break; |
| 3520 | } |
| 3521 | } |
| 3522 | return __first; |
| 3523 | } |
| 3524 | |
| 3525 | template <class _CharT, class _Traits> |
| 3526 | template <class _ForwardIterator> |
| 3527 | _ForwardIterator |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3528 | basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first, |
| 3529 | _ForwardIterator __last) |
| 3530 | { |
| 3531 | if (__first != __last && *__first == '[') |
| 3532 | { |
| 3533 | if (++__first == __last) |
| 3534 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3535 | bool __negate = false; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3536 | if (*__first == '^') |
| 3537 | { |
| 3538 | ++__first; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3539 | __negate = true; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3540 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3541 | __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate); |
| 3542 | // __ml owned by *this |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3543 | if (__first == __last) |
| 3544 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3545 | if ((__flags_ & 0x1F0) != ECMAScript && *__first == ']') |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3546 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3547 | __ml->__add_char(']'); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3548 | ++__first; |
| 3549 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3550 | __first = __parse_follow_list(__first, __last, __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3551 | if (__first == __last) |
| 3552 | throw regex_error(regex_constants::error_brack); |
| 3553 | if (*__first == '-') |
| 3554 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3555 | __ml->__add_char('-'); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3556 | ++__first; |
| 3557 | } |
| 3558 | if (__first == __last || *__first != ']') |
| 3559 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3560 | ++__first; |
| 3561 | } |
| 3562 | return __first; |
| 3563 | } |
| 3564 | |
| 3565 | template <class _CharT, class _Traits> |
| 3566 | template <class _ForwardIterator> |
| 3567 | _ForwardIterator |
| 3568 | basic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3569 | _ForwardIterator __last, |
| 3570 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3571 | { |
| 3572 | if (__first != __last) |
| 3573 | { |
| 3574 | while (true) |
| 3575 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3576 | _ForwardIterator __temp = __parse_expression_term(__first, __last, |
| 3577 | __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3578 | if (__temp == __first) |
| 3579 | break; |
| 3580 | __first = __temp; |
| 3581 | } |
| 3582 | } |
| 3583 | return __first; |
| 3584 | } |
| 3585 | |
| 3586 | template <class _CharT, class _Traits> |
| 3587 | template <class _ForwardIterator> |
| 3588 | _ForwardIterator |
| 3589 | basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3590 | _ForwardIterator __last, |
| 3591 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3592 | { |
| 3593 | if (__first != __last && *__first != ']') |
| 3594 | { |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3595 | _ForwardIterator __temp = next(__first); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3596 | basic_string<_CharT> __start_range; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3597 | if (__temp != __last && *__first == '[') |
| 3598 | { |
| 3599 | if (*__temp == '=') |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3600 | return __parse_equivalence_class(++__temp, __last, __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3601 | else if (*__temp == ':') |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3602 | return __parse_character_class(++__temp, __last, __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3603 | else if (*__temp == '.') |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3604 | __first = __parse_collating_symbol(++__temp, __last, __start_range); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3605 | } |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3606 | unsigned __grammar = __flags_ & 0x1F0; |
| 3607 | if (__start_range.empty()) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3608 | { |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3609 | if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') |
| 3610 | { |
| 3611 | if (__grammar == ECMAScript) |
| 3612 | __first = __parse_class_escape(++__first, __last, __start_range, __ml); |
| 3613 | else |
| 3614 | __first = __parse_awk_escape(++__first, __last, &__start_range); |
| 3615 | } |
| 3616 | else |
| 3617 | { |
| 3618 | __start_range = *__first; |
| 3619 | ++__first; |
| 3620 | } |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3621 | } |
| 3622 | if (__first != __last && *__first != ']') |
| 3623 | { |
| 3624 | __temp = next(__first); |
| 3625 | if (__temp != __last && *__first == '-' && *__temp != ']') |
| 3626 | { |
| 3627 | // parse a range |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3628 | basic_string<_CharT> __end_range; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3629 | __first = __temp; |
| 3630 | ++__temp; |
| 3631 | if (__temp != __last && *__first == '[' && *__temp == '.') |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3632 | __first = __parse_collating_symbol(++__temp, __last, __end_range); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3633 | else |
| 3634 | { |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3635 | if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') |
| 3636 | { |
| 3637 | if (__grammar == ECMAScript) |
| 3638 | __first = __parse_class_escape(++__first, __last, |
| 3639 | __end_range, __ml); |
| 3640 | else |
| 3641 | __first = __parse_awk_escape(++__first, __last, |
| 3642 | &__end_range); |
| 3643 | } |
| 3644 | else |
| 3645 | { |
| 3646 | __end_range = *__first; |
| 3647 | ++__first; |
| 3648 | } |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3649 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3650 | __ml->__add_range(_STD::move(__start_range), _STD::move(__end_range)); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3651 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3652 | else |
| 3653 | { |
| 3654 | if (__start_range.size() == 1) |
| 3655 | __ml->__add_char(__start_range[0]); |
| 3656 | else |
| 3657 | __ml->__add_digraph(__start_range[0], __start_range[1]); |
| 3658 | } |
| 3659 | } |
| 3660 | else |
| 3661 | { |
| 3662 | if (__start_range.size() == 1) |
| 3663 | __ml->__add_char(__start_range[0]); |
| 3664 | else |
| 3665 | __ml->__add_digraph(__start_range[0], __start_range[1]); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3666 | } |
| 3667 | } |
| 3668 | return __first; |
| 3669 | } |
| 3670 | |
| 3671 | template <class _CharT, class _Traits> |
| 3672 | template <class _ForwardIterator> |
| 3673 | _ForwardIterator |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3674 | basic_regex<_CharT, _Traits>::__parse_class_escape(_ForwardIterator __first, |
| 3675 | _ForwardIterator __last, |
| 3676 | basic_string<_CharT>& __str, |
| 3677 | __bracket_expression<_CharT, _Traits>* __ml) |
| 3678 | { |
| 3679 | if (__first == __last) |
| 3680 | throw regex_error(regex_constants::error_escape); |
| 3681 | switch (*__first) |
| 3682 | { |
| 3683 | case 0: |
| 3684 | __str = *__first; |
| 3685 | return ++__first; |
| 3686 | case 'b': |
| 3687 | __str = _CharT(8); |
| 3688 | return ++__first; |
| 3689 | case 'd': |
| 3690 | __ml->__add_class(ctype_base::digit); |
| 3691 | return ++__first; |
| 3692 | case 'D': |
| 3693 | __ml->__add_neg_class(ctype_base::digit); |
| 3694 | return ++__first; |
| 3695 | case 's': |
| 3696 | __ml->__add_class(ctype_base::space); |
| 3697 | return ++__first; |
| 3698 | case 'S': |
| 3699 | __ml->__add_neg_class(ctype_base::space); |
| 3700 | return ++__first; |
| 3701 | case 'w': |
| 3702 | __ml->__add_class(ctype_base::alnum); |
| 3703 | __ml->__add_char('_'); |
| 3704 | return ++__first; |
| 3705 | case 'W': |
| 3706 | __ml->__add_neg_class(ctype_base::alnum); |
| 3707 | __ml->__add_neg_char('_'); |
| 3708 | return ++__first; |
| 3709 | } |
| 3710 | __first = __parse_character_escape(__first, __last, &__str); |
| 3711 | return __first; |
| 3712 | } |
| 3713 | |
| 3714 | template <class _CharT, class _Traits> |
| 3715 | template <class _ForwardIterator> |
| 3716 | _ForwardIterator |
| 3717 | basic_regex<_CharT, _Traits>::__parse_awk_escape(_ForwardIterator __first, |
| 3718 | _ForwardIterator __last, |
| 3719 | basic_string<_CharT>* __str) |
| 3720 | { |
| 3721 | if (__first == __last) |
| 3722 | throw regex_error(regex_constants::error_escape); |
| 3723 | switch (*__first) |
| 3724 | { |
| 3725 | case '\\': |
| 3726 | case '"': |
| 3727 | case '/': |
| 3728 | if (__str) |
| 3729 | *__str = *__first; |
| 3730 | else |
| 3731 | __push_char(*__first); |
| 3732 | return ++__first; |
| 3733 | case 'a': |
| 3734 | if (__str) |
| 3735 | *__str = _CharT(7); |
| 3736 | else |
| 3737 | __push_char(_CharT(7)); |
| 3738 | return ++__first; |
| 3739 | case 'b': |
| 3740 | if (__str) |
| 3741 | *__str = _CharT(8); |
| 3742 | else |
| 3743 | __push_char(_CharT(8)); |
| 3744 | return ++__first; |
| 3745 | case 'f': |
| 3746 | if (__str) |
| 3747 | *__str = _CharT(0xC); |
| 3748 | else |
| 3749 | __push_char(_CharT(0xC)); |
| 3750 | return ++__first; |
| 3751 | case 'n': |
| 3752 | if (__str) |
| 3753 | *__str = _CharT(0xA); |
| 3754 | else |
| 3755 | __push_char(_CharT(0xA)); |
| 3756 | return ++__first; |
| 3757 | case 'r': |
| 3758 | if (__str) |
| 3759 | *__str = _CharT(0xD); |
| 3760 | else |
| 3761 | __push_char(_CharT(0xD)); |
| 3762 | return ++__first; |
| 3763 | case 't': |
| 3764 | if (__str) |
| 3765 | *__str = _CharT(0x9); |
| 3766 | else |
| 3767 | __push_char(_CharT(0x9)); |
| 3768 | return ++__first; |
| 3769 | case 'v': |
| 3770 | if (__str) |
| 3771 | *__str = _CharT(0xB); |
| 3772 | else |
| 3773 | __push_char(_CharT(0xB)); |
| 3774 | return ++__first; |
| 3775 | } |
| 3776 | if ('0' <= *__first && *__first <= '7') |
| 3777 | { |
| 3778 | unsigned __val = *__first - '0'; |
| 3779 | if (++__first != __last && ('0' <= *__first && *__first <= '7')) |
| 3780 | { |
| 3781 | __val = 8 * __val + *__first - '0'; |
| 3782 | if (++__first != __last && ('0' <= *__first && *__first <= '7')) |
| 3783 | __val = 8 * __val + *__first - '0'; |
| 3784 | } |
| 3785 | if (__str) |
| 3786 | *__str = _CharT(__val); |
| 3787 | else |
| 3788 | __push_char(_CharT(__val)); |
| 3789 | } |
| 3790 | else |
| 3791 | throw regex_error(regex_constants::error_escape); |
| 3792 | return __first; |
| 3793 | } |
| 3794 | |
| 3795 | template <class _CharT, class _Traits> |
| 3796 | template <class _ForwardIterator> |
| 3797 | _ForwardIterator |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3798 | basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3799 | _ForwardIterator __last, |
| 3800 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3801 | { |
| 3802 | // Found [= |
| 3803 | // This means =] must exist |
| 3804 | value_type _Equal_close[2] = {'=', ']'}; |
| 3805 | _ForwardIterator __temp = _STD::search(__first, __last, _Equal_close, |
| 3806 | _Equal_close+2); |
| 3807 | if (__temp == __last) |
| 3808 | throw regex_error(regex_constants::error_brack); |
| 3809 | // [__first, __temp) contains all text in [= ... =] |
| 3810 | typedef typename _Traits::string_type string_type; |
| 3811 | string_type __collate_name = |
| 3812 | __traits_.lookup_collatename(__first, __temp); |
| 3813 | if (__collate_name.empty()) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3814 | throw regex_error(regex_constants::error_collate); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3815 | string_type __equiv_name = |
| 3816 | __traits_.transform_primary(__collate_name.begin(), |
| 3817 | __collate_name.end()); |
| 3818 | if (!__equiv_name.empty()) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3819 | __ml->__add_equivalence(__equiv_name); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3820 | else |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3821 | { |
| 3822 | switch (__collate_name.size()) |
| 3823 | { |
| 3824 | case 1: |
| 3825 | __ml->__add_char(__collate_name[0]); |
| 3826 | break; |
| 3827 | case 2: |
| 3828 | __ml->__add_digraph(__collate_name[0], __collate_name[1]); |
| 3829 | break; |
| 3830 | default: |
| 3831 | throw regex_error(regex_constants::error_collate); |
| 3832 | } |
| 3833 | } |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3834 | __first = next(__temp, 2); |
| 3835 | return __first; |
| 3836 | } |
| 3837 | |
| 3838 | template <class _CharT, class _Traits> |
| 3839 | template <class _ForwardIterator> |
| 3840 | _ForwardIterator |
| 3841 | basic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3842 | _ForwardIterator __last, |
| 3843 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3844 | { |
| 3845 | // Found [: |
| 3846 | // This means :] must exist |
| 3847 | value_type _Colon_close[2] = {':', ']'}; |
| 3848 | _ForwardIterator __temp = _STD::search(__first, __last, _Colon_close, |
| 3849 | _Colon_close+2); |
| 3850 | if (__temp == __last) |
| 3851 | throw regex_error(regex_constants::error_brack); |
| 3852 | // [__first, __temp) contains all text in [: ... :] |
| 3853 | typedef typename _Traits::char_class_type char_class_type; |
| 3854 | char_class_type __class_type = |
| 3855 | __traits_.lookup_classname(__first, __temp, __flags_ & icase); |
| 3856 | if (__class_type == 0) |
| 3857 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3858 | __ml->__add_class(__class_type); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3859 | __first = next(__temp, 2); |
| 3860 | return __first; |
| 3861 | } |
| 3862 | |
| 3863 | template <class _CharT, class _Traits> |
| 3864 | template <class _ForwardIterator> |
| 3865 | _ForwardIterator |
| 3866 | basic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3867 | _ForwardIterator __last, |
| 3868 | basic_string<_CharT>& __col_sym) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3869 | { |
| 3870 | // Found [. |
| 3871 | // This means .] must exist |
| 3872 | value_type _Dot_close[2] = {'.', ']'}; |
| 3873 | _ForwardIterator __temp = _STD::search(__first, __last, _Dot_close, |
| 3874 | _Dot_close+2); |
| 3875 | if (__temp == __last) |
| 3876 | throw regex_error(regex_constants::error_brack); |
| 3877 | // [__first, __temp) contains all text in [. ... .] |
| 3878 | typedef typename _Traits::string_type string_type; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3879 | __col_sym = __traits_.lookup_collatename(__first, __temp); |
| 3880 | switch (__col_sym.size()) |
| 3881 | { |
| 3882 | case 1: |
| 3883 | case 2: |
| 3884 | break; |
| 3885 | default: |
| 3886 | throw regex_error(regex_constants::error_collate); |
| 3887 | } |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3888 | __first = next(__temp, 2); |
| 3889 | return __first; |
| 3890 | } |
| 3891 | |
| 3892 | template <class _CharT, class _Traits> |
| 3893 | template <class _ForwardIterator> |
| 3894 | _ForwardIterator |
| 3895 | basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first, |
| 3896 | _ForwardIterator __last, |
| 3897 | int& __c) |
| 3898 | { |
| 3899 | if (__first != __last && '0' <= *__first && *__first <= '9') |
| 3900 | { |
| 3901 | __c = *__first - '0'; |
| 3902 | for (++__first; __first != __last && '0' <= *__first && *__first <= '9'; |
| 3903 | ++__first) |
| 3904 | { |
| 3905 | __c *= 10; |
| 3906 | __c += *__first - '0'; |
| 3907 | } |
| 3908 | } |
| 3909 | return __first; |
| 3910 | } |
| 3911 | |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3912 | template <class _CharT, class _Traits> |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 3913 | template <class _ForwardIterator> |
| 3914 | _ForwardIterator |
| 3915 | basic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first, |
| 3916 | _ForwardIterator __last) |
| 3917 | { |
| 3918 | __owns_one_state<_CharT>* __sa = __end_; |
| 3919 | _ForwardIterator __temp = __parse_alternative(__first, __last); |
| 3920 | if (__temp == __first) |
| 3921 | __push_empty(); |
| 3922 | __first = __temp; |
| 3923 | while (__first != __last && *__first == '|') |
| 3924 | { |
| 3925 | __owns_one_state<_CharT>* __sb = __end_; |
| 3926 | __temp = __parse_alternative(++__first, __last); |
| 3927 | if (__temp == __first) |
| 3928 | __push_empty(); |
| 3929 | __push_alternation(__sa, __sb); |
| 3930 | __first = __temp; |
| 3931 | } |
| 3932 | return __first; |
| 3933 | } |
| 3934 | |
| 3935 | template <class _CharT, class _Traits> |
| 3936 | template <class _ForwardIterator> |
| 3937 | _ForwardIterator |
| 3938 | basic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first, |
| 3939 | _ForwardIterator __last) |
| 3940 | { |
| 3941 | while (true) |
| 3942 | { |
| 3943 | _ForwardIterator __temp = __parse_term(__first, __last); |
| 3944 | if (__temp == __first) |
| 3945 | break; |
| 3946 | __first = __temp; |
| 3947 | } |
| 3948 | return __first; |
| 3949 | } |
| 3950 | |
| 3951 | template <class _CharT, class _Traits> |
| 3952 | template <class _ForwardIterator> |
| 3953 | _ForwardIterator |
| 3954 | basic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first, |
| 3955 | _ForwardIterator __last) |
| 3956 | { |
| 3957 | _ForwardIterator __temp = __parse_assertion(__first, __last); |
| 3958 | if (__temp == __first) |
| 3959 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3960 | __owns_one_state<_CharT>* __e = __end_; |
| 3961 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 3962 | __temp = __parse_atom(__first, __last); |
| 3963 | if (__temp != __first) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3964 | __first = __parse_ERE_dupl_symbol(__temp, __last, __e, |
| 3965 | __mexp_begin+1, __marked_count_+1); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 3966 | } |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3967 | else |
| 3968 | __first = __temp; |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 3969 | return __first; |
| 3970 | } |
| 3971 | |
| 3972 | template <class _CharT, class _Traits> |
| 3973 | template <class _ForwardIterator> |
| 3974 | _ForwardIterator |
| 3975 | basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first, |
| 3976 | _ForwardIterator __last) |
| 3977 | { |
| 3978 | if (__first != __last) |
| 3979 | { |
| 3980 | switch (*__first) |
| 3981 | { |
| 3982 | case '^': |
| 3983 | __push_l_anchor(); |
| 3984 | ++__first; |
| 3985 | break; |
| 3986 | case '$': |
| 3987 | __push_r_anchor(); |
| 3988 | ++__first; |
| 3989 | break; |
| 3990 | case '\\': |
| 3991 | { |
| 3992 | _ForwardIterator __temp = _STD::next(__first); |
| 3993 | if (__temp != __last) |
| 3994 | { |
| 3995 | if (*__temp == 'b') |
| 3996 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3997 | __push_word_boundary(false); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 3998 | __first = ++__temp; |
| 3999 | } |
| 4000 | else if (*__temp == 'B') |
| 4001 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4002 | __push_word_boundary(true); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4003 | __first = ++__temp; |
| 4004 | } |
| 4005 | } |
| 4006 | } |
| 4007 | break; |
| 4008 | case '(': |
| 4009 | { |
| 4010 | _ForwardIterator __temp = _STD::next(__first); |
| 4011 | if (__temp != __last && *__temp == '?') |
| 4012 | { |
| 4013 | if (++__temp != __last) |
| 4014 | { |
| 4015 | switch (*__temp) |
| 4016 | { |
| 4017 | case '=': |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4018 | { |
| 4019 | basic_regex __exp; |
| 4020 | __exp.__flags_ = __flags_; |
| 4021 | __temp = __exp.__parse(++__temp, __last); |
| 4022 | __exp.__push_l_anchor(); |
| 4023 | __push_lookahead(_STD::move(__exp), false); |
| 4024 | if (__temp == __last || *__temp != ')') |
| 4025 | throw regex_error(regex_constants::error_paren); |
| 4026 | __first = ++__temp; |
| 4027 | } |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4028 | break; |
| 4029 | case '!': |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4030 | { |
| 4031 | basic_regex __exp; |
| 4032 | __exp.__flags_ = __flags_; |
| 4033 | __temp = __exp.__parse(++__temp, __last); |
| 4034 | __exp.__push_l_anchor(); |
| 4035 | __push_lookahead(_STD::move(__exp), true); |
| 4036 | if (__temp == __last || *__temp != ')') |
| 4037 | throw regex_error(regex_constants::error_paren); |
| 4038 | __first = ++__temp; |
| 4039 | } |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4040 | break; |
| 4041 | } |
| 4042 | } |
| 4043 | } |
| 4044 | } |
| 4045 | break; |
| 4046 | } |
| 4047 | } |
| 4048 | return __first; |
| 4049 | } |
| 4050 | |
| 4051 | template <class _CharT, class _Traits> |
| 4052 | template <class _ForwardIterator> |
| 4053 | _ForwardIterator |
| 4054 | basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first, |
| 4055 | _ForwardIterator __last) |
| 4056 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4057 | if (__first != __last) |
| 4058 | { |
| 4059 | switch (*__first) |
| 4060 | { |
| 4061 | case '.': |
| 4062 | __push_match_any_but_newline(); |
| 4063 | ++__first; |
| 4064 | break; |
| 4065 | case '\\': |
| 4066 | __first = __parse_atom_escape(__first, __last); |
| 4067 | break; |
| 4068 | case '[': |
| 4069 | __first = __parse_bracket_expression(__first, __last); |
| 4070 | break; |
| 4071 | case '(': |
| 4072 | { |
| 4073 | if (++__first == __last) |
| 4074 | throw regex_error(regex_constants::error_paren); |
| 4075 | _ForwardIterator __temp = _STD::next(__first); |
| 4076 | if (__temp != __last && *__first == '?' && *__temp == ':') |
| 4077 | { |
| 4078 | ++__open_count_; |
| 4079 | __first = __parse_ecma_exp(++__temp, __last); |
| 4080 | if (__first == __last || *__first != ')') |
| 4081 | throw regex_error(regex_constants::error_paren); |
| 4082 | --__open_count_; |
| 4083 | ++__first; |
| 4084 | } |
| 4085 | else |
| 4086 | { |
| 4087 | __push_begin_marked_subexpression(); |
| 4088 | unsigned __temp_count = __marked_count_; |
| 4089 | ++__open_count_; |
| 4090 | __first = __parse_ecma_exp(__first, __last); |
| 4091 | if (__first == __last || *__first != ')') |
| 4092 | throw regex_error(regex_constants::error_paren); |
| 4093 | __push_end_marked_subexpression(__temp_count); |
| 4094 | --__open_count_; |
| 4095 | ++__first; |
| 4096 | } |
| 4097 | } |
| 4098 | break; |
| 4099 | default: |
| 4100 | __first = __parse_pattern_character(__first, __last); |
| 4101 | break; |
| 4102 | } |
| 4103 | } |
| 4104 | return __first; |
| 4105 | } |
| 4106 | |
| 4107 | template <class _CharT, class _Traits> |
| 4108 | template <class _ForwardIterator> |
| 4109 | _ForwardIterator |
| 4110 | basic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first, |
| 4111 | _ForwardIterator __last) |
| 4112 | { |
| 4113 | if (__first != __last && *__first == '\\') |
| 4114 | { |
| 4115 | _ForwardIterator __t1 = _STD::next(__first); |
| 4116 | _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last); |
| 4117 | if (__t2 != __t1) |
| 4118 | __first = __t2; |
| 4119 | else |
| 4120 | { |
| 4121 | __t2 = __parse_character_class_escape(__t1, __last); |
| 4122 | if (__t2 != __t1) |
| 4123 | __first = __t2; |
| 4124 | else |
| 4125 | { |
| 4126 | __t2 = __parse_character_escape(__t1, __last); |
| 4127 | if (__t2 != __t1) |
| 4128 | __first = __t2; |
| 4129 | } |
| 4130 | } |
| 4131 | } |
| 4132 | return __first; |
| 4133 | } |
| 4134 | |
| 4135 | template <class _CharT, class _Traits> |
| 4136 | template <class _ForwardIterator> |
| 4137 | _ForwardIterator |
| 4138 | basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first, |
| 4139 | _ForwardIterator __last) |
| 4140 | { |
| 4141 | if (__first != __last) |
| 4142 | { |
| 4143 | if (*__first == '0') |
| 4144 | { |
| 4145 | __push_char(_CharT()); |
| 4146 | ++__first; |
| 4147 | } |
| 4148 | else if ('1' <= *__first && *__first <= '9') |
| 4149 | { |
| 4150 | unsigned __v = *__first - '0'; |
| 4151 | for (++__first; '0' <= *__first && *__first <= '9'; ++__first) |
| 4152 | __v = 10 * __v + *__first - '0'; |
| 4153 | if (__v > mark_count()) |
| 4154 | throw regex_error(regex_constants::error_backref); |
| 4155 | __push_back_ref(__v); |
| 4156 | } |
| 4157 | } |
| 4158 | return __first; |
| 4159 | } |
| 4160 | |
| 4161 | template <class _CharT, class _Traits> |
| 4162 | template <class _ForwardIterator> |
| 4163 | _ForwardIterator |
| 4164 | basic_regex<_CharT, _Traits>::__parse_character_class_escape(_ForwardIterator __first, |
| 4165 | _ForwardIterator __last) |
| 4166 | { |
| 4167 | if (__first != __last) |
| 4168 | { |
| 4169 | __bracket_expression<_CharT, _Traits>* __ml; |
| 4170 | switch (*__first) |
| 4171 | { |
| 4172 | case 'd': |
| 4173 | __ml = __start_matching_list(false); |
| 4174 | __ml->__add_class(ctype_base::digit); |
| 4175 | ++__first; |
| 4176 | break; |
| 4177 | case 'D': |
| 4178 | __ml = __start_matching_list(true); |
| 4179 | __ml->__add_class(ctype_base::digit); |
| 4180 | ++__first; |
| 4181 | break; |
| 4182 | case 's': |
| 4183 | __ml = __start_matching_list(false); |
| 4184 | __ml->__add_class(ctype_base::space); |
| 4185 | ++__first; |
| 4186 | break; |
| 4187 | case 'S': |
| 4188 | __ml = __start_matching_list(true); |
| 4189 | __ml->__add_class(ctype_base::space); |
| 4190 | ++__first; |
| 4191 | break; |
| 4192 | case 'w': |
| 4193 | __ml = __start_matching_list(false); |
| 4194 | __ml->__add_class(ctype_base::alnum); |
| 4195 | __ml->__add_char('_'); |
| 4196 | ++__first; |
| 4197 | break; |
| 4198 | case 'W': |
| 4199 | __ml = __start_matching_list(true); |
| 4200 | __ml->__add_class(ctype_base::alnum); |
| 4201 | __ml->__add_char('_'); |
| 4202 | ++__first; |
| 4203 | break; |
| 4204 | } |
| 4205 | } |
| 4206 | return __first; |
| 4207 | } |
| 4208 | |
| 4209 | template <class _CharT, class _Traits> |
| 4210 | template <class _ForwardIterator> |
| 4211 | _ForwardIterator |
| 4212 | basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first, |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4213 | _ForwardIterator __last, |
| 4214 | basic_string<_CharT>* __str) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4215 | { |
| 4216 | if (__first != __last) |
| 4217 | { |
| 4218 | _ForwardIterator __t; |
| 4219 | unsigned __sum = 0; |
| 4220 | int __hd; |
| 4221 | switch (*__first) |
| 4222 | { |
| 4223 | case 'f': |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4224 | if (__str) |
| 4225 | *__str = _CharT(0xC); |
| 4226 | else |
| 4227 | __push_char(_CharT(0xC)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4228 | ++__first; |
| 4229 | break; |
| 4230 | case 'n': |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4231 | if (__str) |
| 4232 | *__str = _CharT(0xA); |
| 4233 | else |
| 4234 | __push_char(_CharT(0xA)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4235 | ++__first; |
| 4236 | break; |
| 4237 | case 'r': |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4238 | if (__str) |
| 4239 | *__str = _CharT(0xD); |
| 4240 | else |
| 4241 | __push_char(_CharT(0xD)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4242 | ++__first; |
| 4243 | break; |
| 4244 | case 't': |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4245 | if (__str) |
| 4246 | *__str = _CharT(0x9); |
| 4247 | else |
| 4248 | __push_char(_CharT(0x9)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4249 | ++__first; |
| 4250 | break; |
| 4251 | case 'v': |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4252 | if (__str) |
| 4253 | *__str = _CharT(0xB); |
| 4254 | else |
| 4255 | __push_char(_CharT(0xB)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4256 | ++__first; |
| 4257 | break; |
| 4258 | case 'c': |
| 4259 | if ((__t = _STD::next(__first)) != __last) |
| 4260 | { |
| 4261 | if ('A' <= *__t <= 'Z' || 'a' <= *__t <= 'z') |
| 4262 | { |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4263 | if (__str) |
| 4264 | *__str = _CharT(*__t % 32); |
| 4265 | else |
| 4266 | __push_char(_CharT(*__t % 32)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4267 | __first = ++__t; |
| 4268 | } |
| 4269 | } |
| 4270 | break; |
| 4271 | case 'u': |
| 4272 | if (++__first == __last) |
| 4273 | throw regex_error(regex_constants::error_escape); |
| 4274 | __hd = __traits_.value(*__first, 16); |
| 4275 | if (__hd == -1) |
| 4276 | throw regex_error(regex_constants::error_escape); |
| 4277 | __sum = 16 * __sum + __hd; |
| 4278 | if (++__first == __last) |
| 4279 | throw regex_error(regex_constants::error_escape); |
| 4280 | __hd = __traits_.value(*__first, 16); |
| 4281 | if (__hd == -1) |
| 4282 | throw regex_error(regex_constants::error_escape); |
| 4283 | __sum = 16 * __sum + __hd; |
| 4284 | // drop through |
| 4285 | case 'x': |
| 4286 | if (++__first == __last) |
| 4287 | throw regex_error(regex_constants::error_escape); |
| 4288 | __hd = __traits_.value(*__first, 16); |
| 4289 | if (__hd == -1) |
| 4290 | throw regex_error(regex_constants::error_escape); |
| 4291 | __sum = 16 * __sum + __hd; |
| 4292 | if (++__first == __last) |
| 4293 | throw regex_error(regex_constants::error_escape); |
| 4294 | __hd = __traits_.value(*__first, 16); |
| 4295 | if (__hd == -1) |
| 4296 | throw regex_error(regex_constants::error_escape); |
| 4297 | __sum = 16 * __sum + __hd; |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4298 | if (__str) |
| 4299 | *__str = _CharT(__sum); |
| 4300 | else |
| 4301 | __push_char(_CharT(__sum)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4302 | ++__first; |
| 4303 | break; |
| 4304 | default: |
| 4305 | if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum)) |
| 4306 | { |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4307 | if (__str) |
| 4308 | *__str = *__first; |
| 4309 | else |
| 4310 | __push_char(*__first); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4311 | ++__first; |
| 4312 | } |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4313 | else if (__str) |
| 4314 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4315 | break; |
| 4316 | } |
| 4317 | } |
| 4318 | return __first; |
| 4319 | } |
| 4320 | |
| 4321 | template <class _CharT, class _Traits> |
| 4322 | template <class _ForwardIterator> |
| 4323 | _ForwardIterator |
| 4324 | basic_regex<_CharT, _Traits>::__parse_pattern_character(_ForwardIterator __first, |
| 4325 | _ForwardIterator __last) |
| 4326 | { |
| 4327 | if (__first != __last) |
| 4328 | { |
| 4329 | switch (*__first) |
| 4330 | { |
| 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 | case '|': |
| 4345 | break; |
| 4346 | default: |
| 4347 | __push_char(*__first); |
| 4348 | ++__first; |
| 4349 | break; |
| 4350 | } |
| 4351 | } |
| 4352 | return __first; |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4353 | } |
| 4354 | |
| 4355 | template <class _CharT, class _Traits> |
Howard Hinnant | 856846b | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4356 | template <class _ForwardIterator> |
| 4357 | _ForwardIterator |
| 4358 | basic_regex<_CharT, _Traits>::__parse_grep(_ForwardIterator __first, |
| 4359 | _ForwardIterator __last) |
| 4360 | { |
| 4361 | __owns_one_state<_CharT>* __sa = __end_; |
| 4362 | _ForwardIterator __t1 = _STD::find(__first, __last, _CharT('\n')); |
| 4363 | if (__t1 != __first) |
| 4364 | __parse_basic_reg_exp(__first, __t1); |
| 4365 | else |
| 4366 | __push_empty(); |
| 4367 | __first = __t1; |
| 4368 | if (__first != __last) |
| 4369 | ++__first; |
| 4370 | while (__first != __last) |
| 4371 | { |
| 4372 | __t1 = _STD::find(__first, __last, _CharT('\n')); |
| 4373 | __owns_one_state<_CharT>* __sb = __end_; |
| 4374 | if (__t1 != __first) |
| 4375 | __parse_basic_reg_exp(__first, __t1); |
| 4376 | else |
| 4377 | __push_empty(); |
| 4378 | __push_alternation(__sa, __sb); |
| 4379 | __first = __t1; |
| 4380 | if (__first != __last) |
| 4381 | ++__first; |
| 4382 | } |
| 4383 | return __first; |
| 4384 | } |
| 4385 | |
| 4386 | template <class _CharT, class _Traits> |
| 4387 | template <class _ForwardIterator> |
| 4388 | _ForwardIterator |
| 4389 | basic_regex<_CharT, _Traits>::__parse_egrep(_ForwardIterator __first, |
| 4390 | _ForwardIterator __last) |
| 4391 | { |
| 4392 | __owns_one_state<_CharT>* __sa = __end_; |
| 4393 | _ForwardIterator __t1 = _STD::find(__first, __last, _CharT('\n')); |
| 4394 | if (__t1 != __first) |
| 4395 | __parse_extended_reg_exp(__first, __t1); |
| 4396 | else |
| 4397 | __push_empty(); |
| 4398 | __first = __t1; |
| 4399 | if (__first != __last) |
| 4400 | ++__first; |
| 4401 | while (__first != __last) |
| 4402 | { |
| 4403 | __t1 = _STD::find(__first, __last, _CharT('\n')); |
| 4404 | __owns_one_state<_CharT>* __sb = __end_; |
| 4405 | if (__t1 != __first) |
| 4406 | __parse_extended_reg_exp(__first, __t1); |
| 4407 | else |
| 4408 | __push_empty(); |
| 4409 | __push_alternation(__sa, __sb); |
| 4410 | __first = __t1; |
| 4411 | if (__first != __last) |
| 4412 | ++__first; |
| 4413 | } |
| 4414 | return __first; |
| 4415 | } |
| 4416 | |
| 4417 | template <class _CharT, class _Traits> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4418 | void |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4419 | basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max, |
| 4420 | __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end, |
| 4421 | bool __greedy) |
| 4422 | { |
| 4423 | unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first())); |
| 4424 | __end_->first() = nullptr; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4425 | unique_ptr<__loop<_CharT> > __e2(new __loop<_CharT>(__loop_count_, |
| 4426 | __s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy, |
| 4427 | __min, __max)); |
| 4428 | __s->first() = nullptr; |
| 4429 | __e1.release(); |
| 4430 | __end_->first() = new __repeat_one_loop<_CharT>(__e2.get()); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4431 | __end_ = __e2->second(); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4432 | __s->first() = __e2.release(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4433 | ++__loop_count_; |
| 4434 | } |
| 4435 | |
| 4436 | template <class _CharT, class _Traits> |
| 4437 | void |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4438 | basic_regex<_CharT, _Traits>::__push_char(value_type __c) |
| 4439 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4440 | if (flags() & icase) |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4441 | __end_->first() = new __match_char_icase<_CharT, _Traits> |
| 4442 | (__traits_, __c, __end_->first()); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4443 | else if (flags() & collate) |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4444 | __end_->first() = new __match_char_collate<_CharT, _Traits> |
| 4445 | (__traits_, __c, __end_->first()); |
| 4446 | else |
| 4447 | __end_->first() = new __match_char<_CharT>(__c, __end_->first()); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 4448 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4449 | } |
| 4450 | |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4451 | template <class _CharT, class _Traits> |
| 4452 | void |
| 4453 | basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression() |
| 4454 | { |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 4455 | if (!(__flags_ & nosubs)) |
| 4456 | { |
| 4457 | __end_->first() = |
| 4458 | new __begin_marked_subexpression<_CharT>(++__marked_count_, |
| 4459 | __end_->first()); |
| 4460 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4461 | } |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4462 | } |
| 4463 | |
| 4464 | template <class _CharT, class _Traits> |
| 4465 | void |
| 4466 | basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub) |
| 4467 | { |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 4468 | if (!(__flags_ & nosubs)) |
| 4469 | { |
| 4470 | __end_->first() = |
| 4471 | new __end_marked_subexpression<_CharT>(__sub, __end_->first()); |
| 4472 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4473 | } |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4474 | } |
| 4475 | |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4476 | template <class _CharT, class _Traits> |
| 4477 | void |
| 4478 | basic_regex<_CharT, _Traits>::__push_r_anchor() |
| 4479 | { |
| 4480 | __end_->first() = new __r_anchor<_CharT>(__end_->first()); |
| 4481 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4482 | } |
| 4483 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4484 | template <class _CharT, class _Traits> |
| 4485 | void |
| 4486 | basic_regex<_CharT, _Traits>::__push_match_any() |
| 4487 | { |
| 4488 | __end_->first() = new __match_any<_CharT>(__end_->first()); |
| 4489 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4490 | } |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4491 | |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4492 | template <class _CharT, class _Traits> |
| 4493 | void |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4494 | basic_regex<_CharT, _Traits>::__push_match_any_but_newline() |
| 4495 | { |
| 4496 | __end_->first() = new __match_any_but_newline<_CharT>(__end_->first()); |
| 4497 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4498 | } |
| 4499 | |
| 4500 | template <class _CharT, class _Traits> |
| 4501 | void |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4502 | basic_regex<_CharT, _Traits>::__push_empty() |
| 4503 | { |
| 4504 | __end_->first() = new __empty_state<_CharT>(__end_->first()); |
| 4505 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4506 | } |
| 4507 | |
| 4508 | template <class _CharT, class _Traits> |
| 4509 | void |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4510 | basic_regex<_CharT, _Traits>::__push_word_boundary(bool __invert) |
| 4511 | { |
| 4512 | __end_->first() = new __word_boundary<_CharT, _Traits>(__traits_, __invert, |
| 4513 | __end_->first()); |
| 4514 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4515 | } |
| 4516 | |
| 4517 | template <class _CharT, class _Traits> |
| 4518 | void |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4519 | basic_regex<_CharT, _Traits>::__push_back_ref(int __i) |
| 4520 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4521 | if (flags() & icase) |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4522 | __end_->first() = new __back_ref_icase<_CharT, _Traits> |
| 4523 | (__traits_, __i, __end_->first()); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4524 | else if (flags() & collate) |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4525 | __end_->first() = new __back_ref_collate<_CharT, _Traits> |
| 4526 | (__traits_, __i, __end_->first()); |
| 4527 | else |
| 4528 | __end_->first() = new __back_ref<_CharT>(__i, __end_->first()); |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4529 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4530 | } |
| 4531 | |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4532 | template <class _CharT, class _Traits> |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 4533 | void |
| 4534 | basic_regex<_CharT, _Traits>::__push_alternation(__owns_one_state<_CharT>* __sa, |
| 4535 | __owns_one_state<_CharT>* __ea) |
| 4536 | { |
| 4537 | __sa->first() = new __alternate<_CharT>( |
| 4538 | static_cast<__owns_one_state<_CharT>*>(__sa->first()), |
| 4539 | static_cast<__owns_one_state<_CharT>*>(__ea->first())); |
| 4540 | __ea->first() = nullptr; |
| 4541 | __ea->first() = new __empty_state<_CharT>(__end_->first()); |
| 4542 | __end_->first() = nullptr; |
| 4543 | __end_->first() = new __empty_non_own_state<_CharT>(__ea->first()); |
| 4544 | __end_ = static_cast<__owns_one_state<_CharT>*>(__ea->first()); |
| 4545 | } |
| 4546 | |
| 4547 | template <class _CharT, class _Traits> |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4548 | __bracket_expression<_CharT, _Traits>* |
| 4549 | basic_regex<_CharT, _Traits>::__start_matching_list(bool __negate) |
| 4550 | { |
| 4551 | __bracket_expression<_CharT, _Traits>* __r = |
| 4552 | new __bracket_expression<_CharT, _Traits>(__traits_, __end_->first(), |
| 4553 | __negate, __flags_ & icase, |
| 4554 | __flags_ & collate); |
| 4555 | __end_->first() = __r; |
| 4556 | __end_ = __r; |
| 4557 | return __r; |
| 4558 | } |
| 4559 | |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4560 | template <class _CharT, class _Traits> |
| 4561 | void |
| 4562 | basic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp, |
| 4563 | bool __invert) |
| 4564 | { |
| 4565 | __end_->first() = new __lookahead<_CharT, _Traits>(__exp, __invert, |
| 4566 | __end_->first()); |
| 4567 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4568 | } |
| 4569 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 4570 | typedef basic_regex<char> regex; |
| 4571 | typedef basic_regex<wchar_t> wregex; |
| 4572 | |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4573 | // sub_match |
| 4574 | |
| 4575 | template <class _BidirectionalIterator> |
| 4576 | class sub_match |
| 4577 | : public pair<_BidirectionalIterator, _BidirectionalIterator> |
| 4578 | { |
| 4579 | public: |
| 4580 | typedef _BidirectionalIterator iterator; |
| 4581 | typedef typename iterator_traits<iterator>::value_type value_type; |
| 4582 | typedef typename iterator_traits<iterator>::difference_type difference_type; |
| 4583 | typedef basic_string<value_type> string_type; |
| 4584 | |
| 4585 | bool matched; |
| 4586 | |
| 4587 | difference_type length() const |
| 4588 | {return matched ? _STD::distance(this->first, this->second) : 0;} |
| 4589 | string_type str() const |
| 4590 | {return matched ? string_type(this->first, this->second) : string_type();} |
| 4591 | operator string_type() const |
| 4592 | {return str();} |
| 4593 | |
| 4594 | int compare(const sub_match& __s) const |
| 4595 | {return str().compare(__s.str());} |
| 4596 | int compare(const string_type& __s) const |
| 4597 | {return str().compare(__s);} |
| 4598 | int compare(const value_type* __s) const |
| 4599 | {return str().compare(__s);} |
| 4600 | }; |
| 4601 | |
| 4602 | typedef sub_match<const char*> csub_match; |
| 4603 | typedef sub_match<const wchar_t*> wcsub_match; |
| 4604 | typedef sub_match<string::const_iterator> ssub_match; |
| 4605 | typedef sub_match<wstring::const_iterator> wssub_match; |
| 4606 | |
| 4607 | template <class _BiIter> |
| 4608 | inline _LIBCPP_INLINE_VISIBILITY |
| 4609 | bool |
| 4610 | operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4611 | { |
| 4612 | return __x.compare(__y) == 0; |
| 4613 | } |
| 4614 | |
| 4615 | template <class _BiIter> |
| 4616 | inline _LIBCPP_INLINE_VISIBILITY |
| 4617 | bool |
| 4618 | operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4619 | { |
| 4620 | return !(__x == __y); |
| 4621 | } |
| 4622 | |
| 4623 | template <class _BiIter> |
| 4624 | inline _LIBCPP_INLINE_VISIBILITY |
| 4625 | bool |
| 4626 | operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4627 | { |
| 4628 | return __x.compare(__y) < 0; |
| 4629 | } |
| 4630 | |
| 4631 | template <class _BiIter> |
| 4632 | inline _LIBCPP_INLINE_VISIBILITY |
| 4633 | bool |
| 4634 | operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4635 | { |
| 4636 | return !(__y < __x); |
| 4637 | } |
| 4638 | |
| 4639 | template <class _BiIter> |
| 4640 | inline _LIBCPP_INLINE_VISIBILITY |
| 4641 | bool |
| 4642 | operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4643 | { |
| 4644 | return !(__x < __y); |
| 4645 | } |
| 4646 | |
| 4647 | template <class _BiIter> |
| 4648 | inline _LIBCPP_INLINE_VISIBILITY |
| 4649 | bool |
| 4650 | operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4651 | { |
| 4652 | return __y < __x; |
| 4653 | } |
| 4654 | |
| 4655 | template <class _BiIter, class _ST, class _SA> |
| 4656 | inline _LIBCPP_INLINE_VISIBILITY |
| 4657 | bool |
| 4658 | operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4659 | const sub_match<_BiIter>& __y) |
| 4660 | { |
| 4661 | return __y.compare(__x.c_str()) == 0; |
| 4662 | } |
| 4663 | |
| 4664 | template <class _BiIter, class _ST, class _SA> |
| 4665 | inline _LIBCPP_INLINE_VISIBILITY |
| 4666 | bool |
| 4667 | operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4668 | const sub_match<_BiIter>& __y) |
| 4669 | { |
| 4670 | return !(__x == __y); |
| 4671 | } |
| 4672 | |
| 4673 | template <class _BiIter, class _ST, class _SA> |
| 4674 | inline _LIBCPP_INLINE_VISIBILITY |
| 4675 | bool |
| 4676 | operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4677 | const sub_match<_BiIter>& __y) |
| 4678 | { |
| 4679 | return __y.compare(__x.c_str()) > 0; |
| 4680 | } |
| 4681 | |
| 4682 | template <class _BiIter, class _ST, class _SA> |
| 4683 | inline _LIBCPP_INLINE_VISIBILITY |
| 4684 | bool |
| 4685 | operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4686 | const sub_match<_BiIter>& __y) |
| 4687 | { |
| 4688 | return __y < __x; |
| 4689 | } |
| 4690 | |
| 4691 | template <class _BiIter, class _ST, class _SA> |
| 4692 | inline _LIBCPP_INLINE_VISIBILITY |
| 4693 | bool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4694 | const sub_match<_BiIter>& __y) |
| 4695 | { |
| 4696 | return !(__x < __y); |
| 4697 | } |
| 4698 | |
| 4699 | template <class _BiIter, class _ST, class _SA> |
| 4700 | inline _LIBCPP_INLINE_VISIBILITY |
| 4701 | bool |
| 4702 | operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4703 | const sub_match<_BiIter>& __y) |
| 4704 | { |
| 4705 | return !(__y < __x); |
| 4706 | } |
| 4707 | |
| 4708 | template <class _BiIter, class _ST, class _SA> |
| 4709 | inline _LIBCPP_INLINE_VISIBILITY |
| 4710 | bool |
| 4711 | operator==(const sub_match<_BiIter>& __x, |
| 4712 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4713 | { |
| 4714 | return __x.compare(__y.c_str()) == 0; |
| 4715 | } |
| 4716 | |
| 4717 | template <class _BiIter, class _ST, class _SA> |
| 4718 | inline _LIBCPP_INLINE_VISIBILITY |
| 4719 | bool |
| 4720 | operator!=(const sub_match<_BiIter>& __x, |
| 4721 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4722 | { |
| 4723 | return !(__x == __y); |
| 4724 | } |
| 4725 | |
| 4726 | template <class _BiIter, class _ST, class _SA> |
| 4727 | inline _LIBCPP_INLINE_VISIBILITY |
| 4728 | bool |
| 4729 | operator<(const sub_match<_BiIter>& __x, |
| 4730 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4731 | { |
| 4732 | return __x.compare(__y.c_str()) < 0; |
| 4733 | } |
| 4734 | |
| 4735 | template <class _BiIter, class _ST, class _SA> |
| 4736 | inline _LIBCPP_INLINE_VISIBILITY |
| 4737 | bool operator>(const sub_match<_BiIter>& __x, |
| 4738 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4739 | { |
| 4740 | return __y < __x; |
| 4741 | } |
| 4742 | |
| 4743 | template <class _BiIter, class _ST, class _SA> |
| 4744 | inline _LIBCPP_INLINE_VISIBILITY |
| 4745 | bool |
| 4746 | operator>=(const sub_match<_BiIter>& __x, |
| 4747 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4748 | { |
| 4749 | return !(__x < __y); |
| 4750 | } |
| 4751 | |
| 4752 | template <class _BiIter, class _ST, class _SA> |
| 4753 | inline _LIBCPP_INLINE_VISIBILITY |
| 4754 | bool |
| 4755 | operator<=(const sub_match<_BiIter>& __x, |
| 4756 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4757 | { |
| 4758 | return !(__y < __x); |
| 4759 | } |
| 4760 | |
| 4761 | template <class _BiIter> |
| 4762 | inline _LIBCPP_INLINE_VISIBILITY |
| 4763 | bool |
| 4764 | operator==(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4765 | const sub_match<_BiIter>& __y) |
| 4766 | { |
| 4767 | return __y.compare(__x) == 0; |
| 4768 | } |
| 4769 | |
| 4770 | template <class _BiIter> |
| 4771 | inline _LIBCPP_INLINE_VISIBILITY |
| 4772 | bool |
| 4773 | operator!=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4774 | const sub_match<_BiIter>& __y) |
| 4775 | { |
| 4776 | return !(__x == __y); |
| 4777 | } |
| 4778 | |
| 4779 | template <class _BiIter> |
| 4780 | inline _LIBCPP_INLINE_VISIBILITY |
| 4781 | bool |
| 4782 | operator<(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4783 | const sub_match<_BiIter>& __y) |
| 4784 | { |
| 4785 | return __y.compare(__x) > 0; |
| 4786 | } |
| 4787 | |
| 4788 | template <class _BiIter> |
| 4789 | inline _LIBCPP_INLINE_VISIBILITY |
| 4790 | bool |
| 4791 | operator>(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4792 | const sub_match<_BiIter>& __y) |
| 4793 | { |
| 4794 | return __y < __x; |
| 4795 | } |
| 4796 | |
| 4797 | template <class _BiIter> |
| 4798 | inline _LIBCPP_INLINE_VISIBILITY |
| 4799 | bool |
| 4800 | operator>=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4801 | const sub_match<_BiIter>& __y) |
| 4802 | { |
| 4803 | return !(__x < __y); |
| 4804 | } |
| 4805 | |
| 4806 | template <class _BiIter> |
| 4807 | inline _LIBCPP_INLINE_VISIBILITY |
| 4808 | bool |
| 4809 | operator<=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4810 | const sub_match<_BiIter>& __y) |
| 4811 | { |
| 4812 | return !(__y < __x); |
| 4813 | } |
| 4814 | |
| 4815 | template <class _BiIter> |
| 4816 | inline _LIBCPP_INLINE_VISIBILITY |
| 4817 | bool |
| 4818 | operator==(const sub_match<_BiIter>& __x, |
| 4819 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 4820 | { |
| 4821 | return __x.compare(__y) == 0; |
| 4822 | } |
| 4823 | |
| 4824 | template <class _BiIter> |
| 4825 | inline _LIBCPP_INLINE_VISIBILITY |
| 4826 | bool |
| 4827 | operator!=(const sub_match<_BiIter>& __x, |
| 4828 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 4829 | { |
| 4830 | return !(__x == __y); |
| 4831 | } |
| 4832 | |
| 4833 | template <class _BiIter> |
| 4834 | inline _LIBCPP_INLINE_VISIBILITY |
| 4835 | bool |
| 4836 | operator<(const sub_match<_BiIter>& __x, |
| 4837 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 4838 | { |
| 4839 | return __x.compare(__y) < 0; |
| 4840 | } |
| 4841 | |
| 4842 | template <class _BiIter> |
| 4843 | inline _LIBCPP_INLINE_VISIBILITY |
| 4844 | bool |
| 4845 | operator>(const sub_match<_BiIter>& __x, |
| 4846 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 4847 | { |
| 4848 | return __y < __x; |
| 4849 | } |
| 4850 | |
| 4851 | template <class _BiIter> |
| 4852 | inline _LIBCPP_INLINE_VISIBILITY |
| 4853 | bool |
| 4854 | operator>=(const sub_match<_BiIter>& __x, |
| 4855 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 4856 | { |
| 4857 | return !(__x < __y); |
| 4858 | } |
| 4859 | |
| 4860 | template <class _BiIter> |
| 4861 | inline _LIBCPP_INLINE_VISIBILITY |
| 4862 | bool |
| 4863 | operator<=(const sub_match<_BiIter>& __x, |
| 4864 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 4865 | { |
| 4866 | return !(__y < __x); |
| 4867 | } |
| 4868 | |
| 4869 | template <class _BiIter> |
| 4870 | inline _LIBCPP_INLINE_VISIBILITY |
| 4871 | bool |
| 4872 | operator==(typename iterator_traits<_BiIter>::value_type const& __x, |
| 4873 | const sub_match<_BiIter>& __y) |
| 4874 | { |
| 4875 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 4876 | return __y.compare(string_type(1, __x)) == 0; |
| 4877 | } |
| 4878 | |
| 4879 | template <class _BiIter> |
| 4880 | inline _LIBCPP_INLINE_VISIBILITY |
| 4881 | bool |
| 4882 | operator!=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 4883 | const sub_match<_BiIter>& __y) |
| 4884 | { |
| 4885 | return !(__x == __y); |
| 4886 | } |
| 4887 | |
| 4888 | template <class _BiIter> |
| 4889 | inline _LIBCPP_INLINE_VISIBILITY |
| 4890 | bool |
| 4891 | operator<(typename iterator_traits<_BiIter>::value_type const& __x, |
| 4892 | const sub_match<_BiIter>& __y) |
| 4893 | { |
| 4894 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 4895 | return __y.compare(string_type(1, __x)) > 0; |
| 4896 | } |
| 4897 | |
| 4898 | template <class _BiIter> |
| 4899 | inline _LIBCPP_INLINE_VISIBILITY |
| 4900 | bool |
| 4901 | operator>(typename iterator_traits<_BiIter>::value_type const& __x, |
| 4902 | const sub_match<_BiIter>& __y) |
| 4903 | { |
| 4904 | return __y < __x; |
| 4905 | } |
| 4906 | |
| 4907 | template <class _BiIter> |
| 4908 | inline _LIBCPP_INLINE_VISIBILITY |
| 4909 | bool |
| 4910 | operator>=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 4911 | const sub_match<_BiIter>& __y) |
| 4912 | { |
| 4913 | return !(__x < __y); |
| 4914 | } |
| 4915 | |
| 4916 | template <class _BiIter> |
| 4917 | inline _LIBCPP_INLINE_VISIBILITY |
| 4918 | bool |
| 4919 | operator<=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 4920 | const sub_match<_BiIter>& __y) |
| 4921 | { |
| 4922 | return !(__y < __x); |
| 4923 | } |
| 4924 | |
| 4925 | template <class _BiIter> |
| 4926 | inline _LIBCPP_INLINE_VISIBILITY |
| 4927 | bool |
| 4928 | operator==(const sub_match<_BiIter>& __x, |
| 4929 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 4930 | { |
| 4931 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 4932 | return __x.compare(string_type(1, __y)) == 0; |
| 4933 | } |
| 4934 | |
| 4935 | template <class _BiIter> |
| 4936 | inline _LIBCPP_INLINE_VISIBILITY |
| 4937 | bool |
| 4938 | operator!=(const sub_match<_BiIter>& __x, |
| 4939 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 4940 | { |
| 4941 | return !(__x == __y); |
| 4942 | } |
| 4943 | |
| 4944 | template <class _BiIter> |
| 4945 | inline _LIBCPP_INLINE_VISIBILITY |
| 4946 | bool |
| 4947 | operator<(const sub_match<_BiIter>& __x, |
| 4948 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 4949 | { |
| 4950 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 4951 | return __x.compare(string_type(1, __y)) < 0; |
| 4952 | } |
| 4953 | |
| 4954 | template <class _BiIter> |
| 4955 | inline _LIBCPP_INLINE_VISIBILITY |
| 4956 | bool |
| 4957 | operator>(const sub_match<_BiIter>& __x, |
| 4958 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 4959 | { |
| 4960 | return __y < __x; |
| 4961 | } |
| 4962 | |
| 4963 | template <class _BiIter> |
| 4964 | inline _LIBCPP_INLINE_VISIBILITY |
| 4965 | bool |
| 4966 | operator>=(const sub_match<_BiIter>& __x, |
| 4967 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 4968 | { |
| 4969 | return !(__x < __y); |
| 4970 | } |
| 4971 | |
| 4972 | template <class _BiIter> |
| 4973 | inline _LIBCPP_INLINE_VISIBILITY |
| 4974 | bool |
| 4975 | operator<=(const sub_match<_BiIter>& __x, |
| 4976 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 4977 | { |
| 4978 | return !(__y < __x); |
| 4979 | } |
| 4980 | |
| 4981 | template <class _CharT, class _ST, class _BiIter> |
| 4982 | inline _LIBCPP_INLINE_VISIBILITY |
| 4983 | basic_ostream<_CharT, _ST>& |
| 4984 | operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m) |
| 4985 | { |
| 4986 | return __os << __m.str(); |
| 4987 | } |
| 4988 | |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4989 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 4990 | class match_results |
| 4991 | { |
| 4992 | public: |
| 4993 | typedef _Allocator allocator_type; |
| 4994 | typedef sub_match<_BidirectionalIterator> value_type; |
| 4995 | private: |
| 4996 | typedef vector<value_type, allocator_type> __container_type; |
| 4997 | |
| 4998 | __container_type __matches_; |
| 4999 | value_type __unmatched_; |
| 5000 | value_type __prefix_; |
| 5001 | value_type __suffix_; |
| 5002 | public: |
| 5003 | typedef const value_type& const_reference; |
| 5004 | typedef const_reference reference; |
| 5005 | typedef typename __container_type::const_iterator const_iterator; |
| 5006 | typedef const_iterator iterator; |
| 5007 | typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; |
| 5008 | typedef typename allocator_traits<allocator_type>::size_type size_type; |
| 5009 | typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type; |
| 5010 | typedef basic_string<char_type> string_type; |
| 5011 | |
| 5012 | // construct/copy/destroy: |
| 5013 | explicit match_results(const allocator_type& __a = allocator_type()); |
| 5014 | // match_results(const match_results&) = default; |
| 5015 | // match_results& operator=(const match_results&) = default; |
| 5016 | #ifdef _LIBCPP_MOVE |
| 5017 | // match_results(match_results&& __m) = default; |
| 5018 | // match_results& operator=(match_results&& __m) = default; |
| 5019 | #endif |
| 5020 | // ~match_results() = default; |
| 5021 | |
| 5022 | // size: |
| 5023 | size_type size() const {return __matches_.size();} |
| 5024 | size_type max_size() const {return __matches_.max_size();} |
| 5025 | bool empty() const {return size() == 0;} |
| 5026 | |
| 5027 | // element access: |
| 5028 | difference_type length(size_type __sub = 0) const |
| 5029 | {return (*this)[__sub].length();} |
| 5030 | difference_type position(size_type __sub = 0) const |
| 5031 | {return _STD::distance(__prefix_.first, (*this)[__sub].first);} |
| 5032 | string_type str(size_type __sub = 0) const |
| 5033 | {return (*this)[__sub].str();} |
| 5034 | const_reference operator[](size_type __n) const |
| 5035 | {return __n < __matches_.size() ? __matches_[__n] : __unmatched_;} |
| 5036 | |
| 5037 | const_reference prefix() const {return __prefix_;} |
| 5038 | const_reference suffix() const {return __suffix_;} |
| 5039 | |
| 5040 | const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin() + 1;} |
| 5041 | const_iterator end() const {return __matches_.end();} |
| 5042 | const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin() + 1;} |
| 5043 | const_iterator cend() const {return __matches_.end();} |
| 5044 | |
| 5045 | // format: |
| 5046 | template <class _OutputIter> |
| 5047 | _OutputIter |
| 5048 | format(_OutputIter __out, const char_type* __fmt_first, |
| 5049 | const char_type* __fmt_last, |
| 5050 | regex_constants::match_flag_type __flags = regex_constants::format_default) const; |
| 5051 | template <class _OutputIter, class _ST, class _SA> |
| 5052 | _OutputIter |
| 5053 | format(_OutputIter __out, const basic_string<char_type, _ST, _SA>& __fmt, |
| 5054 | regex_constants::match_flag_type __flags = regex_constants::format_default) const; |
| 5055 | template <class _ST, class _SA> |
| 5056 | basic_string<char_type, _ST, _SA> |
| 5057 | format(const basic_string<char_type, _ST, _SA>& __fmt, |
| 5058 | regex_constants::match_flag_type __flags = regex_constants::format_default) const; |
| 5059 | string_type |
| 5060 | format(const char_type* __fmt, |
| 5061 | regex_constants::match_flag_type __flags = regex_constants::format_default) const; |
| 5062 | |
| 5063 | // allocator: |
| 5064 | allocator_type get_allocator() const {return __matches_.get_allocator();} |
| 5065 | |
| 5066 | // swap: |
| 5067 | void swap(match_results& __m); |
| 5068 | |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5069 | template <class _B, class _A> |
| 5070 | void __assign(_BidirectionalIterator __f, _BidirectionalIterator __l, |
| 5071 | const match_results<_B, _A>& __m) |
| 5072 | { |
| 5073 | _B __mf = __m.prefix().first; |
| 5074 | __matches_.resize(__m.size()); |
| 5075 | for (size_type __i = 0; __i < __matches_.size(); ++__i) |
| 5076 | { |
| 5077 | __matches_[__i].first = next(__f, _STD::distance(__mf, __m[__i].first)); |
| 5078 | __matches_[__i].second = next(__f, _STD::distance(__mf, __m[__i].second)); |
| 5079 | __matches_[__i].matched = __m[__i].matched; |
| 5080 | } |
| 5081 | __unmatched_.first = __l; |
| 5082 | __unmatched_.second = __l; |
| 5083 | __unmatched_.matched = false; |
| 5084 | __prefix_.first = next(__f, _STD::distance(__mf, __m.prefix().first)); |
| 5085 | __prefix_.second = next(__f, _STD::distance(__mf, __m.prefix().second)); |
| 5086 | __prefix_.matched = __m.prefix().matched; |
| 5087 | __suffix_.first = next(__f, _STD::distance(__mf, __m.suffix().first)); |
| 5088 | __suffix_.second = next(__f, _STD::distance(__mf, __m.suffix().second)); |
| 5089 | __suffix_.matched = __m.suffix().matched; |
| 5090 | } |
| 5091 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5092 | private: |
| 5093 | void __init(unsigned __s, |
| 5094 | _BidirectionalIterator __f, _BidirectionalIterator __l); |
| 5095 | |
| 5096 | template <class, class> friend class basic_regex; |
| 5097 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5098 | template <class _B, class _A, class _C, class _T> |
| 5099 | friend |
| 5100 | bool |
| 5101 | regex_match(_B, _B, match_results<_B, _A>&, const basic_regex<_C, _T>&, |
| 5102 | regex_constants::match_flag_type); |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 5103 | |
| 5104 | template <class, class> friend class __lookahead; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5105 | }; |
| 5106 | |
| 5107 | template <class _BidirectionalIterator, class _Allocator> |
| 5108 | match_results<_BidirectionalIterator, _Allocator>::match_results( |
| 5109 | const allocator_type& __a) |
| 5110 | : __matches_(__a), |
| 5111 | __unmatched_(), |
| 5112 | __prefix_(), |
| 5113 | __suffix_() |
| 5114 | { |
| 5115 | } |
| 5116 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5117 | template <class _BidirectionalIterator, class _Allocator> |
| 5118 | void |
| 5119 | match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s, |
| 5120 | _BidirectionalIterator __f, _BidirectionalIterator __l) |
| 5121 | { |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5122 | __unmatched_.first = __l; |
| 5123 | __unmatched_.second = __l; |
| 5124 | __unmatched_.matched = false; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5125 | __matches_.assign(__s, __unmatched_); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5126 | __prefix_.first = __f; |
| 5127 | __prefix_.second = __f; |
| 5128 | __prefix_.matched = false; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5129 | __suffix_ = __unmatched_; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5130 | } |
| 5131 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5132 | typedef match_results<const char*> cmatch; |
| 5133 | typedef match_results<const wchar_t*> wcmatch; |
| 5134 | typedef match_results<string::const_iterator> smatch; |
| 5135 | typedef match_results<wstring::const_iterator> wsmatch; |
| 5136 | |
| 5137 | template <class _BidirectionalIterator, class _Allocator> |
| 5138 | bool |
| 5139 | operator==(const match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5140 | const match_results<_BidirectionalIterator, _Allocator>& __y); |
| 5141 | |
| 5142 | template <class _BidirectionalIterator, class _Allocator> |
| 5143 | bool |
| 5144 | operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5145 | const match_results<_BidirectionalIterator, _Allocator>& __y); |
| 5146 | |
| 5147 | template <class _BidirectionalIterator, class _Allocator> |
| 5148 | void |
| 5149 | swap(match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5150 | match_results<_BidirectionalIterator, _Allocator>& __y); |
| 5151 | |
| 5152 | // regex_search |
| 5153 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5154 | template <class _CharT, class _Traits> |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5155 | template <class _Allocator> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5156 | bool |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5157 | basic_regex<_CharT, _Traits>::__match_at_start_ecma( |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5158 | const _CharT* __first, const _CharT* __last, |
| 5159 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5160 | regex_constants::match_flag_type __flags) const |
| 5161 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5162 | vector<__state> __states; |
| 5163 | ptrdiff_t __j = 0; |
| 5164 | ptrdiff_t _N = _STD::distance(__first, __last); |
| 5165 | __node* __st = __start_.get(); |
| 5166 | if (__st) |
| 5167 | { |
| 5168 | __states.push_back(__state()); |
| 5169 | __states.back().__do_ = 0; |
| 5170 | __states.back().__first_ = __first; |
| 5171 | __states.back().__current_ = __first; |
| 5172 | __states.back().__last_ = __last; |
| 5173 | __states.back().__sub_matches_.resize(mark_count()); |
| 5174 | __states.back().__loop_data_.resize(__loop_count()); |
| 5175 | __states.back().__node_ = __st; |
| 5176 | __states.back().__flags_ = __flags; |
| 5177 | bool __matched = false; |
| 5178 | do |
| 5179 | { |
| 5180 | __state& __s = __states.back(); |
| 5181 | if (__s.__node_) |
| 5182 | __s.__node_->__exec(__s); |
| 5183 | switch (__s.__do_) |
| 5184 | { |
| 5185 | case __state::__end_state: |
| 5186 | __m.__matches_[0].first = __first; |
| 5187 | __m.__matches_[0].second = _STD::next(__first, __s.__current_ - __first); |
| 5188 | __m.__matches_[0].matched = true; |
| 5189 | for (unsigned __i = 0; __i < __s.__sub_matches_.size(); ++__i) |
| 5190 | __m.__matches_[__i+1] = __s.__sub_matches_[__i]; |
| 5191 | return true; |
| 5192 | case __state::__accept_and_consume: |
| 5193 | case __state::__repeat: |
| 5194 | case __state::__accept_but_not_consume: |
| 5195 | break; |
| 5196 | case __state::__split: |
| 5197 | { |
| 5198 | __state __snext = __s; |
| 5199 | __s.__node_->__exec_split(true, __s); |
| 5200 | __snext.__node_->__exec_split(false, __snext); |
| 5201 | __states.push_back(_STD::move(__snext)); |
| 5202 | } |
| 5203 | break; |
| 5204 | case __state::__reject: |
| 5205 | __states.pop_back(); |
| 5206 | break; |
| 5207 | default: |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5208 | throw regex_error(regex_constants::__re_err_unknown); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5209 | break; |
| 5210 | } |
| 5211 | } while (!__states.empty()); |
| 5212 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5213 | return false; |
| 5214 | } |
| 5215 | |
| 5216 | template <class _CharT, class _Traits> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5217 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5218 | bool |
| 5219 | basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs( |
| 5220 | const _CharT* __first, const _CharT* __last, |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5221 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5222 | regex_constants::match_flag_type __flags) const |
| 5223 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5224 | deque<__state> __states; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5225 | ptrdiff_t __highest_j = 0; |
| 5226 | ptrdiff_t _N = _STD::distance(__first, __last); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5227 | __node* __st = __start_.get(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5228 | if (__st) |
| 5229 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5230 | __states.push_back(__state()); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5231 | __states.back().__do_ = 0; |
| 5232 | __states.back().__first_ = __first; |
| 5233 | __states.back().__current_ = __first; |
| 5234 | __states.back().__last_ = __last; |
| 5235 | __states.back().__loop_data_.resize(__loop_count()); |
| 5236 | __states.back().__node_ = __st; |
| 5237 | __states.back().__flags_ = __flags; |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5238 | bool __matched = false; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5239 | do |
| 5240 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5241 | __state& __s = __states.back(); |
| 5242 | if (__s.__node_) |
| 5243 | __s.__node_->__exec(__s); |
| 5244 | switch (__s.__do_) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5245 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5246 | case __state::__end_state: |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5247 | if (!__matched || __highest_j < __s.__current_ - __s.__first_) |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5248 | __highest_j = __s.__current_ - __s.__first_; |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5249 | __matched = true; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5250 | if (__highest_j == _N) |
| 5251 | __states.clear(); |
| 5252 | else |
| 5253 | __states.pop_back(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5254 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5255 | case __state::__consume_input: |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5256 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5257 | case __state::__accept_and_consume: |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5258 | __states.push_front(_STD::move(__s)); |
| 5259 | __states.pop_back(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5260 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5261 | case __state::__repeat: |
| 5262 | case __state::__accept_but_not_consume: |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5263 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5264 | case __state::__split: |
| 5265 | { |
| 5266 | __state __snext = __s; |
| 5267 | __s.__node_->__exec_split(true, __s); |
| 5268 | __snext.__node_->__exec_split(false, __snext); |
| 5269 | __states.push_back(_STD::move(__snext)); |
| 5270 | } |
| 5271 | break; |
| 5272 | case __state::__reject: |
| 5273 | __states.pop_back(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5274 | break; |
| 5275 | default: |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5276 | throw regex_error(regex_constants::__re_err_unknown); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5277 | break; |
| 5278 | } |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5279 | } while (!__states.empty()); |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5280 | if (__matched) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5281 | { |
| 5282 | __m.__matches_[0].first = __first; |
| 5283 | __m.__matches_[0].second = _STD::next(__first, __highest_j); |
| 5284 | __m.__matches_[0].matched = true; |
| 5285 | return true; |
| 5286 | } |
| 5287 | } |
| 5288 | return false; |
| 5289 | } |
| 5290 | |
| 5291 | template <class _CharT, class _Traits> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5292 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5293 | bool |
| 5294 | basic_regex<_CharT, _Traits>::__match_at_start_posix_subs( |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5295 | const _CharT* __first, const _CharT* __last, |
| 5296 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5297 | regex_constants::match_flag_type __flags) const |
| 5298 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5299 | vector<__state> __states; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5300 | __state __best_state; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5301 | ptrdiff_t __j = 0; |
| 5302 | ptrdiff_t __highest_j = 0; |
| 5303 | ptrdiff_t _N = _STD::distance(__first, __last); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5304 | __node* __st = __start_.get(); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5305 | if (__st) |
| 5306 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5307 | __states.push_back(__state()); |
| 5308 | __states.back().__do_ = 0; |
| 5309 | __states.back().__first_ = __first; |
| 5310 | __states.back().__current_ = __first; |
| 5311 | __states.back().__last_ = __last; |
| 5312 | __states.back().__sub_matches_.resize(mark_count()); |
| 5313 | __states.back().__loop_data_.resize(__loop_count()); |
| 5314 | __states.back().__node_ = __st; |
| 5315 | __states.back().__flags_ = __flags; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5316 | const _CharT* __current = __first; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5317 | bool __matched = false; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5318 | do |
| 5319 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5320 | __state& __s = __states.back(); |
| 5321 | if (__s.__node_) |
| 5322 | __s.__node_->__exec(__s); |
| 5323 | switch (__s.__do_) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5324 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5325 | case __state::__end_state: |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5326 | if (!__matched || __highest_j < __s.__current_ - __s.__first_) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5327 | { |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5328 | __highest_j = __s.__current_ - __s.__first_; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5329 | __best_state = __s; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5330 | } |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5331 | __matched = true; |
| 5332 | if (__highest_j == _N) |
| 5333 | __states.clear(); |
| 5334 | else |
| 5335 | __states.pop_back(); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5336 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5337 | case __state::__accept_and_consume: |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 5338 | __j += __s.__current_ - __current; |
| 5339 | __current = __s.__current_; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5340 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5341 | case __state::__repeat: |
| 5342 | case __state::__accept_but_not_consume: |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5343 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5344 | case __state::__split: |
| 5345 | { |
| 5346 | __state __snext = __s; |
| 5347 | __s.__node_->__exec_split(true, __s); |
| 5348 | __snext.__node_->__exec_split(false, __snext); |
| 5349 | __states.push_back(_STD::move(__snext)); |
| 5350 | } |
| 5351 | break; |
| 5352 | case __state::__reject: |
| 5353 | __states.pop_back(); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5354 | break; |
| 5355 | default: |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5356 | throw regex_error(regex_constants::__re_err_unknown); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5357 | break; |
| 5358 | } |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5359 | } while (!__states.empty()); |
| 5360 | if (__matched) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5361 | { |
| 5362 | __m.__matches_[0].first = __first; |
| 5363 | __m.__matches_[0].second = _STD::next(__first, __highest_j); |
| 5364 | __m.__matches_[0].matched = true; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5365 | for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i) |
| 5366 | __m.__matches_[__i+1] = __best_state.__sub_matches_[__i]; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5367 | return true; |
| 5368 | } |
| 5369 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5370 | return false; |
| 5371 | } |
| 5372 | |
| 5373 | template <class _CharT, class _Traits> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5374 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5375 | bool |
| 5376 | basic_regex<_CharT, _Traits>::__match_at_start( |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5377 | const _CharT* __first, const _CharT* __last, |
| 5378 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5379 | regex_constants::match_flag_type __flags) const |
| 5380 | { |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5381 | if ((__flags_ & 0x1F0) == ECMAScript) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5382 | return __match_at_start_ecma(__first, __last, __m, __flags); |
| 5383 | if (mark_count() == 0) |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5384 | return __match_at_start_posix_nosubs(__first, __last, __m, __flags); |
| 5385 | return __match_at_start_posix_subs(__first, __last, __m, __flags); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5386 | } |
| 5387 | |
| 5388 | template <class _CharT, class _Traits> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5389 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5390 | bool |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5391 | basic_regex<_CharT, _Traits>::__search( |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5392 | const _CharT* __first, const _CharT* __last, |
| 5393 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5394 | regex_constants::match_flag_type __flags) const |
| 5395 | { |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 5396 | if (__left_anchor_) |
| 5397 | __flags |= regex_constants::match_continuous; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5398 | __m.__init(1 + mark_count(), __first, __last); |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5399 | if (__match_at_start(__first, __last, __m, __flags)) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5400 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5401 | __m.__prefix_.second = __m[0].first; |
| 5402 | __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; |
| 5403 | __m.__suffix_.first = __m[0].second; |
| 5404 | __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; |
| 5405 | return true; |
| 5406 | } |
| 5407 | if (!(__flags & regex_constants::match_continuous)) |
| 5408 | { |
| 5409 | __m.__matches_.assign(__m.size(), __m.__unmatched_); |
| 5410 | for (++__first; __first != __last; ++__first) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5411 | { |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5412 | if (__match_at_start(__first, __last, __m, __flags)) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5413 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5414 | __m.__prefix_.second = __m[0].first; |
| 5415 | __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; |
| 5416 | __m.__suffix_.first = __m[0].second; |
| 5417 | __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; |
| 5418 | return true; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5419 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5420 | __m.__matches_.assign(__m.size(), __m.__unmatched_); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5421 | } |
| 5422 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5423 | __m.__matches_.clear(); |
| 5424 | return false; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5425 | } |
| 5426 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5427 | template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5428 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5429 | bool |
| 5430 | regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 5431 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 5432 | const basic_regex<_CharT, _Traits>& __e, |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5433 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5434 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5435 | basic_string<_CharT> __s(__first, __last); |
| 5436 | match_results<const _CharT*> __mc; |
| 5437 | bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
| 5438 | __m.__assign(__first, __last, __mc); |
| 5439 | return __r; |
| 5440 | } |
| 5441 | |
| 5442 | template <class _Allocator, class _CharT, class _Traits> |
| 5443 | inline _LIBCPP_INLINE_VISIBILITY |
| 5444 | bool |
| 5445 | regex_search(const _CharT* __first, const _CharT* __last, |
| 5446 | match_results<const _CharT*, _Allocator>& __m, |
| 5447 | const basic_regex<_CharT, _Traits>& __e, |
| 5448 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5449 | { |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5450 | return __e.__search(__first, __last, __m, __flags); |
| 5451 | } |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5452 | |
| 5453 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 5454 | inline _LIBCPP_INLINE_VISIBILITY |
| 5455 | bool |
| 5456 | regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 5457 | const basic_regex<_CharT, _Traits>& __e, |
| 5458 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5459 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5460 | basic_string<_CharT> __s(__first, __last); |
| 5461 | match_results<const _CharT*> __mc; |
| 5462 | return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
| 5463 | } |
| 5464 | |
| 5465 | template <class _CharT, class _Traits> |
| 5466 | inline _LIBCPP_INLINE_VISIBILITY |
| 5467 | bool |
| 5468 | regex_search(const _CharT* __first, const _CharT* __last, |
| 5469 | const basic_regex<_CharT, _Traits>& __e, |
| 5470 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5471 | { |
| 5472 | match_results<const _CharT*> __mc; |
| 5473 | return __e.__search(__first, __last, __mc, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5474 | } |
| 5475 | |
| 5476 | template <class _CharT, class _Allocator, class _Traits> |
| 5477 | inline _LIBCPP_INLINE_VISIBILITY |
| 5478 | bool |
| 5479 | regex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, |
| 5480 | const basic_regex<_CharT, _Traits>& __e, |
| 5481 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5482 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5483 | return __e.__search(__str, __str + _Traits::length(__str), __m, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5484 | } |
| 5485 | |
| 5486 | template <class _CharT, class _Traits> |
| 5487 | inline _LIBCPP_INLINE_VISIBILITY |
| 5488 | bool |
| 5489 | regex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, |
| 5490 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5491 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5492 | match_results<const _CharT*> __m; |
| 5493 | return _STD::regex_search(__str, __m, __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5494 | } |
| 5495 | |
| 5496 | template <class _ST, class _SA, class _CharT, class _Traits> |
| 5497 | inline _LIBCPP_INLINE_VISIBILITY |
| 5498 | bool |
| 5499 | regex_search(const basic_string<_CharT, _ST, _SA>& __s, |
| 5500 | const basic_regex<_CharT, _Traits>& __e, |
| 5501 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5502 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5503 | match_results<const _CharT*> __mc; |
| 5504 | return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5505 | } |
| 5506 | |
| 5507 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 5508 | inline _LIBCPP_INLINE_VISIBILITY |
| 5509 | bool |
| 5510 | regex_search(const basic_string<_CharT, _ST, _SA>& __s, |
| 5511 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 5512 | const basic_regex<_CharT, _Traits>& __e, |
| 5513 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5514 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5515 | match_results<const _CharT*> __mc; |
| 5516 | bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
| 5517 | __m.__assign(__s.begin(), __s.end(), __mc); |
| 5518 | return __r; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5519 | } |
| 5520 | |
| 5521 | // regex_match |
| 5522 | |
| 5523 | template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> |
| 5524 | bool |
| 5525 | regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 5526 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 5527 | const basic_regex<_CharT, _Traits>& __e, |
| 5528 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5529 | { |
| 5530 | bool __r = _STD::regex_search(__first, __last, __m, __e, |
| 5531 | __flags | regex_constants::match_continuous); |
| 5532 | if (__r) |
| 5533 | { |
| 5534 | __r = !__m.suffix().matched; |
| 5535 | if (!__r) |
| 5536 | __m.__matches_.clear(); |
| 5537 | } |
| 5538 | return __r; |
| 5539 | } |
| 5540 | |
| 5541 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 5542 | inline _LIBCPP_INLINE_VISIBILITY |
| 5543 | bool |
| 5544 | regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 5545 | const basic_regex<_CharT, _Traits>& __e, |
| 5546 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5547 | { |
| 5548 | match_results<_BidirectionalIterator> __m; |
| 5549 | return _STD::regex_match(__first, __last, __m, __e, __flags); |
| 5550 | } |
| 5551 | |
| 5552 | template <class _CharT, class _Allocator, class _Traits> |
| 5553 | inline _LIBCPP_INLINE_VISIBILITY |
| 5554 | bool |
| 5555 | regex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, |
| 5556 | const basic_regex<_CharT, _Traits>& __e, |
| 5557 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5558 | { |
| 5559 | return _STD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags); |
| 5560 | } |
| 5561 | |
| 5562 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 5563 | inline _LIBCPP_INLINE_VISIBILITY |
| 5564 | bool |
| 5565 | regex_match(const basic_string<_CharT, _ST, _SA>& __s, |
| 5566 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 5567 | const basic_regex<_CharT, _Traits>& __e, |
| 5568 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5569 | { |
| 5570 | return _STD::regex_match(__s.begin(), __s.end(), __m, __e, __flags); |
| 5571 | } |
| 5572 | |
| 5573 | template <class _CharT, class _Traits> |
| 5574 | inline _LIBCPP_INLINE_VISIBILITY |
| 5575 | bool |
| 5576 | regex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, |
| 5577 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5578 | { |
| 5579 | return _STD::regex_match(__str, __str + _Traits::length(__str), __e, __flags); |
| 5580 | } |
| 5581 | |
| 5582 | template <class _ST, class _SA, class _CharT, class _Traits> |
| 5583 | inline _LIBCPP_INLINE_VISIBILITY |
| 5584 | bool |
| 5585 | regex_match(const basic_string<_CharT, _ST, _SA>& __s, |
| 5586 | const basic_regex<_CharT, _Traits>& __e, |
| 5587 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5588 | { |
| 5589 | return _STD::regex_match(__s.begin(), __s.end(), __e, __flags); |
| 5590 | } |
| 5591 | |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 5592 | _LIBCPP_END_NAMESPACE_STD |
| 5593 | |
| 5594 | #endif // _LIBCPP_REGEX |