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