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