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 | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 720 | #include <sstream> |
| 721 | #include <cassert> |
| 722 | |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 723 | #include <__config> |
| 724 | #include <stdexcept> |
| 725 | #include <__locale> |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 726 | #include <initializer_list> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 727 | #include <utility> |
| 728 | #include <iterator> |
| 729 | #include <string> |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 730 | #include <memory> |
| 731 | #include <vector> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 732 | #include <__split_buffer> |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 733 | |
| 734 | #pragma GCC system_header |
| 735 | |
| 736 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 737 | |
| 738 | namespace regex_constants |
| 739 | { |
| 740 | |
| 741 | // syntax_option_type |
| 742 | |
| 743 | enum syntax_option_type |
| 744 | { |
| 745 | icase = 1 << 0, |
| 746 | nosubs = 1 << 1, |
| 747 | optimize = 1 << 2, |
| 748 | collate = 1 << 3, |
| 749 | ECMAScript = 1 << 4, |
| 750 | basic = 1 << 5, |
| 751 | extended = 1 << 6, |
| 752 | awk = 1 << 7, |
| 753 | grep = 1 << 8, |
| 754 | egrep = 1 << 9 |
| 755 | }; |
| 756 | |
| 757 | inline |
| 758 | /*constexpr*/ |
| 759 | syntax_option_type |
| 760 | operator~(syntax_option_type __x) |
| 761 | { |
| 762 | return syntax_option_type(~int(__x)); |
| 763 | } |
| 764 | |
| 765 | inline |
| 766 | /*constexpr*/ |
| 767 | syntax_option_type |
| 768 | operator&(syntax_option_type __x, syntax_option_type __y) |
| 769 | { |
| 770 | return syntax_option_type(int(__x) & int(__y)); |
| 771 | } |
| 772 | |
| 773 | inline |
| 774 | /*constexpr*/ |
| 775 | syntax_option_type |
| 776 | operator|(syntax_option_type __x, syntax_option_type __y) |
| 777 | { |
| 778 | return syntax_option_type(int(__x) | int(__y)); |
| 779 | } |
| 780 | |
| 781 | inline |
| 782 | /*constexpr*/ |
| 783 | syntax_option_type |
| 784 | operator^(syntax_option_type __x, syntax_option_type __y) |
| 785 | { |
| 786 | return syntax_option_type(int(__x) ^ int(__y)); |
| 787 | } |
| 788 | |
| 789 | inline |
| 790 | /*constexpr*/ |
| 791 | syntax_option_type& |
| 792 | operator&=(syntax_option_type& __x, syntax_option_type __y) |
| 793 | { |
| 794 | __x = __x & __y; |
| 795 | return __x; |
| 796 | } |
| 797 | |
| 798 | inline |
| 799 | /*constexpr*/ |
| 800 | syntax_option_type& |
| 801 | operator|=(syntax_option_type& __x, syntax_option_type __y) |
| 802 | { |
| 803 | __x = __x | __y; |
| 804 | return __x; |
| 805 | } |
| 806 | |
| 807 | inline |
| 808 | /*constexpr*/ |
| 809 | syntax_option_type& |
| 810 | operator^=(syntax_option_type& __x, syntax_option_type __y) |
| 811 | { |
| 812 | __x = __x ^ __y; |
| 813 | return __x; |
| 814 | } |
| 815 | |
| 816 | // match_flag_type |
| 817 | |
| 818 | enum match_flag_type |
| 819 | { |
| 820 | match_default = 0, |
| 821 | match_not_bol = 1 << 0, |
| 822 | match_not_eol = 1 << 1, |
| 823 | match_not_bow = 1 << 2, |
| 824 | match_not_eow = 1 << 3, |
| 825 | match_any = 1 << 4, |
| 826 | match_not_null = 1 << 5, |
| 827 | match_continuous = 1 << 6, |
| 828 | match_prev_avail = 1 << 7, |
| 829 | format_default = 0, |
| 830 | format_sed = 1 << 8, |
| 831 | format_no_copy = 1 << 9, |
| 832 | format_first_only = 1 << 10 |
| 833 | }; |
| 834 | |
| 835 | inline |
| 836 | /*constexpr*/ |
| 837 | match_flag_type |
| 838 | operator~(match_flag_type __x) |
| 839 | { |
| 840 | return match_flag_type(~int(__x)); |
| 841 | } |
| 842 | |
| 843 | inline |
| 844 | /*constexpr*/ |
| 845 | match_flag_type |
| 846 | operator&(match_flag_type __x, match_flag_type __y) |
| 847 | { |
| 848 | return match_flag_type(int(__x) & int(__y)); |
| 849 | } |
| 850 | |
| 851 | inline |
| 852 | /*constexpr*/ |
| 853 | match_flag_type |
| 854 | operator|(match_flag_type __x, match_flag_type __y) |
| 855 | { |
| 856 | return match_flag_type(int(__x) | int(__y)); |
| 857 | } |
| 858 | |
| 859 | inline |
| 860 | /*constexpr*/ |
| 861 | match_flag_type |
| 862 | operator^(match_flag_type __x, match_flag_type __y) |
| 863 | { |
| 864 | return match_flag_type(int(__x) ^ int(__y)); |
| 865 | } |
| 866 | |
| 867 | inline |
| 868 | /*constexpr*/ |
| 869 | match_flag_type& |
| 870 | operator&=(match_flag_type& __x, match_flag_type __y) |
| 871 | { |
| 872 | __x = __x & __y; |
| 873 | return __x; |
| 874 | } |
| 875 | |
| 876 | inline |
| 877 | /*constexpr*/ |
| 878 | match_flag_type& |
| 879 | operator|=(match_flag_type& __x, match_flag_type __y) |
| 880 | { |
| 881 | __x = __x | __y; |
| 882 | return __x; |
| 883 | } |
| 884 | |
| 885 | inline |
| 886 | /*constexpr*/ |
| 887 | match_flag_type& |
| 888 | operator^=(match_flag_type& __x, match_flag_type __y) |
| 889 | { |
| 890 | __x = __x ^ __y; |
| 891 | return __x; |
| 892 | } |
| 893 | |
| 894 | enum error_type |
| 895 | { |
| 896 | error_collate = 1, |
| 897 | error_ctype, |
| 898 | error_escape, |
| 899 | error_backref, |
| 900 | error_brack, |
| 901 | error_paren, |
| 902 | error_brace, |
| 903 | error_badbrace, |
| 904 | error_range, |
| 905 | error_space, |
| 906 | error_badrepeat, |
| 907 | error_complexity, |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 908 | error_stack, |
| 909 | error_temp |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 910 | }; |
| 911 | |
| 912 | } // regex_constants |
| 913 | |
| 914 | class _LIBCPP_EXCEPTION_ABI regex_error |
| 915 | : public runtime_error |
| 916 | { |
| 917 | regex_constants::error_type __code_; |
| 918 | public: |
| 919 | explicit regex_error(regex_constants::error_type __ecode); |
| 920 | virtual ~regex_error() throw(); |
| 921 | regex_constants::error_type code() const {return __code_;} |
| 922 | }; |
| 923 | |
| 924 | template <class _CharT> |
| 925 | struct regex_traits |
| 926 | { |
| 927 | public: |
| 928 | typedef _CharT char_type; |
| 929 | typedef basic_string<char_type> string_type; |
| 930 | typedef locale locale_type; |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 931 | typedef ctype_base::mask char_class_type; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 932 | |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 933 | static const char_class_type __regex_word = 0x80; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 934 | private: |
| 935 | locale __loc_; |
| 936 | const ctype<char_type>* __ct_; |
| 937 | const collate<char_type>* __col_; |
| 938 | |
| 939 | public: |
| 940 | regex_traits(); |
| 941 | |
| 942 | static size_t length(const char_type* __p) |
| 943 | {return char_traits<char_type>::length(__p);} |
| 944 | char_type translate(char_type __c) const {return __c;} |
| 945 | char_type translate_nocase(char_type __c) const; |
| 946 | template <class _ForwardIterator> |
| 947 | string_type |
| 948 | transform(_ForwardIterator __f, _ForwardIterator __l) const; |
| 949 | template <class _ForwardIterator> |
| 950 | string_type |
| 951 | transform_primary( _ForwardIterator __f, _ForwardIterator __l) const |
| 952 | {return __transform_primary(__f, __l, char_type());} |
| 953 | template <class _ForwardIterator> |
| 954 | string_type |
| 955 | lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const |
| 956 | {return __lookup_collatename(__f, __l, char_type());} |
| 957 | template <class _ForwardIterator> |
| 958 | char_class_type |
| 959 | lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 960 | bool __icase = false) const |
| 961 | {return __lookup_classname(__f, __l, __icase, char_type());} |
| 962 | bool isctype(char_type __c, char_class_type __m) const; |
| 963 | int value(char_type __ch, int __radix) const |
| 964 | {return __value(__ch, __radix);} |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 965 | locale_type imbue(locale_type __l); |
| 966 | locale_type getloc()const {return __loc_;} |
| 967 | |
| 968 | private: |
| 969 | void __init(); |
| 970 | |
| 971 | template <class _ForwardIterator> |
| 972 | string_type |
| 973 | __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const; |
| 974 | template <class _ForwardIterator> |
| 975 | string_type |
| 976 | __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; |
| 977 | |
| 978 | template <class _ForwardIterator> |
| 979 | string_type |
| 980 | __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const; |
| 981 | template <class _ForwardIterator> |
| 982 | string_type |
| 983 | __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 984 | |
| 985 | template <class _ForwardIterator> |
| 986 | char_class_type |
| 987 | __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
| 988 | bool __icase, char) const; |
| 989 | template <class _ForwardIterator> |
| 990 | char_class_type |
| 991 | __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
| 992 | bool __icase, wchar_t) const; |
| 993 | |
| 994 | static int __value(unsigned char __ch, int __radix); |
| 995 | int __value(char __ch, int __radix) const |
| 996 | {return __value(static_cast<unsigned char>(__ch), __radix);} |
| 997 | int __value(wchar_t __ch, int __radix) const; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 998 | }; |
| 999 | |
| 1000 | template <class _CharT> |
| 1001 | regex_traits<_CharT>::regex_traits() |
| 1002 | { |
| 1003 | __init(); |
| 1004 | } |
| 1005 | |
| 1006 | template <class _CharT> |
| 1007 | typename regex_traits<_CharT>::char_type |
| 1008 | regex_traits<_CharT>::translate_nocase(char_type __c) const |
| 1009 | { |
| 1010 | return __ct_->tolower(__c); |
| 1011 | } |
| 1012 | |
| 1013 | template <class _CharT> |
| 1014 | template <class _ForwardIterator> |
| 1015 | typename regex_traits<_CharT>::string_type |
| 1016 | regex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const |
| 1017 | { |
| 1018 | string_type __s(__f, __l); |
| 1019 | return __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1020 | } |
| 1021 | |
| 1022 | template <class _CharT> |
| 1023 | void |
| 1024 | regex_traits<_CharT>::__init() |
| 1025 | { |
| 1026 | __ct_ = &use_facet<ctype<char_type> >(__loc_); |
| 1027 | __col_ = &use_facet<collate<char_type> >(__loc_); |
| 1028 | } |
| 1029 | |
| 1030 | template <class _CharT> |
| 1031 | typename regex_traits<_CharT>::locale_type |
| 1032 | regex_traits<_CharT>::imbue(locale_type __l) |
| 1033 | { |
| 1034 | locale __r = __loc_; |
| 1035 | __loc_ = __l; |
| 1036 | __init(); |
| 1037 | return __r; |
| 1038 | } |
| 1039 | |
| 1040 | // transform_primary is very FreeBSD-specific |
| 1041 | |
| 1042 | template <class _CharT> |
| 1043 | template <class _ForwardIterator> |
| 1044 | typename regex_traits<_CharT>::string_type |
| 1045 | regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, |
| 1046 | _ForwardIterator __l, char) const |
| 1047 | { |
| 1048 | const string_type __s(__f, __l); |
| 1049 | string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1050 | switch (__d.size()) |
| 1051 | { |
| 1052 | case 1: |
| 1053 | break; |
| 1054 | case 12: |
| 1055 | __d[11] = __d[3]; |
| 1056 | break; |
| 1057 | default: |
| 1058 | __d.clear(); |
| 1059 | break; |
| 1060 | } |
| 1061 | return __d; |
| 1062 | } |
| 1063 | |
| 1064 | template <class _CharT> |
| 1065 | template <class _ForwardIterator> |
| 1066 | typename regex_traits<_CharT>::string_type |
| 1067 | regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, |
| 1068 | _ForwardIterator __l, wchar_t) const |
| 1069 | { |
| 1070 | const string_type __s(__f, __l); |
| 1071 | string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1072 | switch (__d.size()) |
| 1073 | { |
| 1074 | case 1: |
| 1075 | break; |
| 1076 | case 3: |
| 1077 | __d[2] = __d[0]; |
| 1078 | break; |
| 1079 | default: |
| 1080 | __d.clear(); |
| 1081 | break; |
| 1082 | } |
| 1083 | return __d; |
| 1084 | } |
| 1085 | |
| 1086 | // lookup_collatename is very FreeBSD-specific |
| 1087 | |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1088 | string __get_collation_name(const char* __s); |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1089 | |
| 1090 | template <class _CharT> |
| 1091 | template <class _ForwardIterator> |
| 1092 | typename regex_traits<_CharT>::string_type |
| 1093 | regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, |
| 1094 | _ForwardIterator __l, char) const |
| 1095 | { |
| 1096 | string_type __s(__f, __l); |
| 1097 | string_type __r; |
| 1098 | if (!__s.empty()) |
| 1099 | { |
| 1100 | __r = __get_collation_name(__s.c_str()); |
| 1101 | if (__r.empty() && __s.size() <= 2) |
| 1102 | { |
| 1103 | __r = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1104 | if (__r.size() == 1 || __r.size() == 12) |
| 1105 | __r = __s; |
| 1106 | else |
| 1107 | __r.clear(); |
| 1108 | } |
| 1109 | } |
| 1110 | return __r; |
| 1111 | } |
| 1112 | |
| 1113 | template <class _CharT> |
| 1114 | template <class _ForwardIterator> |
| 1115 | typename regex_traits<_CharT>::string_type |
| 1116 | regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, |
| 1117 | _ForwardIterator __l, wchar_t) const |
| 1118 | { |
| 1119 | string_type __s(__f, __l); |
| 1120 | string __n; |
| 1121 | __n.reserve(__s.size()); |
| 1122 | for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); |
| 1123 | __i != __e; ++__i) |
| 1124 | { |
| 1125 | if (static_cast<unsigned>(*__i) >= 127) |
| 1126 | return string_type(); |
| 1127 | __n.push_back(char(*__i)); |
| 1128 | } |
| 1129 | string_type __r; |
| 1130 | if (!__s.empty()) |
| 1131 | { |
| 1132 | __n = __get_collation_name(__n.c_str()); |
| 1133 | if (!__n.empty()) |
| 1134 | __r.assign(__n.begin(), __n.end()); |
| 1135 | else if (__s.size() <= 2) |
| 1136 | { |
| 1137 | __r = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1138 | if (__r.size() == 1 || __r.size() == 3) |
| 1139 | __r = __s; |
| 1140 | else |
| 1141 | __r.clear(); |
| 1142 | } |
| 1143 | } |
| 1144 | return __r; |
| 1145 | } |
| 1146 | |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1147 | // lookup_classname |
| 1148 | |
| 1149 | ctype_base::mask __get_classname(const char* __s, bool __icase); |
| 1150 | |
| 1151 | template <class _CharT> |
| 1152 | template <class _ForwardIterator> |
| 1153 | typename regex_traits<_CharT>::char_class_type |
| 1154 | regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, |
| 1155 | _ForwardIterator __l, |
| 1156 | bool __icase, char) const |
| 1157 | { |
| 1158 | string_type __s(__f, __l); |
| 1159 | __ct_->tolower(&__s[0], &__s[0] + __s.size()); |
| 1160 | return __get_classname(__s.c_str(), __icase); |
| 1161 | } |
| 1162 | |
| 1163 | template <class _CharT> |
| 1164 | template <class _ForwardIterator> |
| 1165 | typename regex_traits<_CharT>::char_class_type |
| 1166 | regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, |
| 1167 | _ForwardIterator __l, |
| 1168 | bool __icase, wchar_t) const |
| 1169 | { |
| 1170 | string_type __s(__f, __l); |
| 1171 | __ct_->tolower(&__s[0], &__s[0] + __s.size()); |
| 1172 | string __n; |
| 1173 | __n.reserve(__s.size()); |
| 1174 | for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); |
| 1175 | __i != __e; ++__i) |
| 1176 | { |
| 1177 | if (static_cast<unsigned>(*__i) >= 127) |
| 1178 | return char_class_type(); |
| 1179 | __n.push_back(char(*__i)); |
| 1180 | } |
| 1181 | return __get_classname(__n.c_str(), __icase); |
| 1182 | } |
| 1183 | |
| 1184 | template <class _CharT> |
| 1185 | bool |
| 1186 | regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const |
| 1187 | { |
| 1188 | if (__ct_->is(__m, __c)) |
| 1189 | return true; |
| 1190 | return (__c == '_' && (__m & __regex_word)); |
| 1191 | } |
| 1192 | |
| 1193 | template <class _CharT> |
| 1194 | int |
| 1195 | regex_traits<_CharT>::__value(unsigned char __ch, int __radix) |
| 1196 | { |
| 1197 | if ((__ch & 0xF8u) == 0x30) // '0' <= __ch && __ch <= '7' |
| 1198 | return __ch - '0'; |
| 1199 | if (__radix != 8) |
| 1200 | { |
| 1201 | if ((__ch & 0xFEu) == 0x38) // '8' <= __ch && __ch <= '9' |
| 1202 | return __ch - '0'; |
| 1203 | if (__radix == 16) |
| 1204 | { |
| 1205 | __ch |= 0x20; // tolower |
| 1206 | if ('a' <= __ch && __ch <= 'f') |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 1207 | return __ch - ('a' - 10); |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1208 | } |
| 1209 | } |
| 1210 | return -1; |
| 1211 | } |
| 1212 | |
| 1213 | template <class _CharT> |
| 1214 | inline |
| 1215 | int |
| 1216 | regex_traits<_CharT>::__value(wchar_t __ch, int __radix) const |
| 1217 | { |
| 1218 | return __value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix); |
| 1219 | } |
| 1220 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1221 | template <class _CharT> class __state; |
| 1222 | |
| 1223 | template <class _CharT> |
| 1224 | struct __command |
| 1225 | { |
| 1226 | enum |
| 1227 | { |
| 1228 | __end_state = -1000, |
| 1229 | __consume_input, // -999 |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1230 | __begin_marked_expr, // -998 |
| 1231 | __end_marked_expr, // -997 |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1232 | __pop_state, // -996 |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1233 | __accept_and_consume, // -995 |
| 1234 | __accept_but_not_consume, // -994 |
| 1235 | __reject, // -993 |
| 1236 | __zero_loop_count, |
| 1237 | __increment_loop_count, |
| 1238 | __zero_marked_exprs, |
| 1239 | }; |
| 1240 | |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame^] | 1241 | typedef _STD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1242 | |
| 1243 | int __do_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1244 | const __state* first; |
| 1245 | const __state* second; |
| 1246 | |
| 1247 | __command() : __do_(__reject), first(nullptr), second(nullptr) {} |
| 1248 | explicit __command(int __do) |
| 1249 | : __do_(__do), first(nullptr), second(nullptr) {} |
| 1250 | __command(int __do, const __state* __s1, const __state* __s2 = nullptr) |
| 1251 | : __do_(__do), first(__s1), second(__s2) {} |
| 1252 | explicit __command(const __state* __s1, const __state* __s2 = nullptr) |
| 1253 | : __do_(0), first(__s1), second(__s2) {} |
| 1254 | }; |
| 1255 | |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1256 | template <class _CharT> |
| 1257 | ostream& |
| 1258 | operator<<(ostream& os, const __command<_CharT>& c) |
| 1259 | { |
| 1260 | os << c.__do_; |
| 1261 | if (c.first) |
| 1262 | os << ", " << c.first->speak(); |
| 1263 | if (c.second) |
| 1264 | os << ", " << c.second->speak(); |
| 1265 | return os; |
| 1266 | } |
| 1267 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1268 | template <class _BidirectionalIterator> class sub_match; |
| 1269 | |
| 1270 | // __state |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1271 | |
| 1272 | template <class _CharT> |
| 1273 | class __state |
| 1274 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1275 | __state(const __state&); |
| 1276 | __state& operator=(const __state&); |
| 1277 | public: |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame^] | 1278 | typedef _STD::__command<_CharT> __command; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1279 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1280 | __state() {} |
| 1281 | virtual ~__state() {} |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1282 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1283 | virtual __command __test(const _CharT* __first, const _CharT* __current, |
| 1284 | const _CharT* __last, |
| 1285 | vector<size_t>& __lc, |
| 1286 | sub_match<const _CharT*>* __m, |
| 1287 | regex_constants::match_flag_type __flags) const = 0; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1288 | |
| 1289 | virtual string speak() const = 0; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1290 | }; |
| 1291 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1292 | // __end_state |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1293 | |
| 1294 | template <class _CharT> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1295 | class __end_state |
| 1296 | : public __state<_CharT> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1297 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1298 | public: |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame^] | 1299 | typedef _STD::__command<_CharT> __command; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1300 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1301 | __end_state() {} |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1302 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1303 | virtual __command __test(const _CharT*, const _CharT*, |
| 1304 | const _CharT*, |
| 1305 | vector<size_t>&, |
| 1306 | sub_match<const _CharT*>*, |
| 1307 | regex_constants::match_flag_type) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1308 | |
| 1309 | virtual string speak() const {return "end state";} |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1310 | }; |
| 1311 | |
| 1312 | template <class _CharT> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1313 | __command<_CharT> |
| 1314 | __end_state<_CharT>::__test(const _CharT*, const _CharT*, |
| 1315 | const _CharT*, |
| 1316 | vector<size_t>&, |
| 1317 | sub_match<const _CharT*>*, |
| 1318 | regex_constants::match_flag_type) const |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1319 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1320 | return __command(__command::__end_state); |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1321 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1322 | |
| 1323 | // __has_one_state |
| 1324 | |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1325 | template <class _CharT> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1326 | class __has_one_state |
| 1327 | : public __state<_CharT> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1328 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1329 | __state<_CharT>* __first_; |
| 1330 | |
| 1331 | public: |
| 1332 | explicit __has_one_state(__state<_CharT>* __s) |
| 1333 | : __first_(__s) {} |
| 1334 | |
| 1335 | __state<_CharT>* first() const {return __first_;} |
| 1336 | __state<_CharT>*& first() {return __first_;} |
| 1337 | }; |
| 1338 | |
| 1339 | // __owns_one_state |
| 1340 | |
| 1341 | template <class _CharT> |
| 1342 | class __owns_one_state |
| 1343 | : public __has_one_state<_CharT> |
| 1344 | { |
| 1345 | typedef __has_one_state<_CharT> base; |
| 1346 | |
| 1347 | public: |
| 1348 | explicit __owns_one_state(__state<_CharT>* __s) |
| 1349 | : base(__s) {} |
| 1350 | |
| 1351 | virtual ~__owns_one_state(); |
| 1352 | }; |
| 1353 | |
| 1354 | template <class _CharT> |
| 1355 | __owns_one_state<_CharT>::~__owns_one_state() |
| 1356 | { |
| 1357 | delete this->first(); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1358 | } |
| 1359 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1360 | // __empty_state |
| 1361 | |
| 1362 | template <class _CharT> |
| 1363 | class __empty_state |
| 1364 | : public __owns_one_state<_CharT> |
| 1365 | { |
| 1366 | typedef __owns_one_state<_CharT> base; |
| 1367 | |
| 1368 | public: |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame^] | 1369 | typedef _STD::__command<_CharT> __command; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1370 | |
| 1371 | explicit __empty_state(__state<_CharT>* __s) |
| 1372 | : base(__s) {} |
| 1373 | |
| 1374 | virtual __command __test(const _CharT*, const _CharT*, |
| 1375 | const _CharT*, |
| 1376 | vector<size_t>&, |
| 1377 | sub_match<const _CharT*>*, |
| 1378 | regex_constants::match_flag_type) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1379 | |
| 1380 | virtual string speak() const {return "empty state";} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1381 | }; |
| 1382 | |
| 1383 | template <class _CharT> |
| 1384 | __command<_CharT> |
| 1385 | __empty_state<_CharT>::__test(const _CharT*, const _CharT*, const _CharT*, |
| 1386 | vector<size_t>&, |
| 1387 | sub_match<const _CharT*>*, |
| 1388 | regex_constants::match_flag_type) const |
| 1389 | { |
| 1390 | return __command(__command::__accept_but_not_consume, this->first()); |
| 1391 | } |
| 1392 | |
| 1393 | // __empty_non_own_state |
| 1394 | |
| 1395 | template <class _CharT> |
| 1396 | class __empty_non_own_state |
| 1397 | : public __has_one_state<_CharT> |
| 1398 | { |
| 1399 | typedef __has_one_state<_CharT> base; |
| 1400 | |
| 1401 | public: |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame^] | 1402 | typedef _STD::__command<_CharT> __command; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1403 | |
| 1404 | explicit __empty_non_own_state(__state<_CharT>* __s) |
| 1405 | : base(__s) {} |
| 1406 | |
| 1407 | virtual __command __test(const _CharT*, const _CharT*, |
| 1408 | const _CharT*, |
| 1409 | vector<size_t>&, |
| 1410 | sub_match<const _CharT*>*, |
| 1411 | regex_constants::match_flag_type) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1412 | |
| 1413 | virtual string speak() const {return "empty non-owning state";} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1414 | }; |
| 1415 | |
| 1416 | template <class _CharT> |
| 1417 | __command<_CharT> |
| 1418 | __empty_non_own_state<_CharT>::__test(const _CharT*, const _CharT*, const _CharT*, |
| 1419 | vector<size_t>&, |
| 1420 | sub_match<const _CharT*>*, |
| 1421 | regex_constants::match_flag_type) const |
| 1422 | { |
| 1423 | return __command(__command::__accept_but_not_consume, this->first()); |
| 1424 | } |
| 1425 | |
| 1426 | // __owns_two_states |
| 1427 | |
| 1428 | template <class _CharT> |
| 1429 | class __owns_two_states |
| 1430 | : public __owns_one_state<_CharT> |
| 1431 | { |
| 1432 | typedef __owns_one_state<_CharT> base; |
| 1433 | |
| 1434 | base* __second_; |
| 1435 | |
| 1436 | public: |
| 1437 | explicit __owns_two_states(__state<_CharT>* __s1, base* __s2) |
| 1438 | : base(__s1), __second_(__s2) {} |
| 1439 | |
| 1440 | virtual ~__owns_two_states(); |
| 1441 | |
| 1442 | base* second() const {return __second_;} |
| 1443 | base*& second() {return __second_;} |
| 1444 | }; |
| 1445 | |
| 1446 | template <class _CharT> |
| 1447 | __owns_two_states<_CharT>::~__owns_two_states() |
| 1448 | { |
| 1449 | delete __second_; |
| 1450 | } |
| 1451 | |
| 1452 | // __loop |
| 1453 | |
| 1454 | template <class _CharT> |
| 1455 | class __loop |
| 1456 | : public __owns_two_states<_CharT> |
| 1457 | { |
| 1458 | typedef __owns_two_states<_CharT> base; |
| 1459 | |
| 1460 | size_t __min_; |
| 1461 | size_t __max_; |
| 1462 | unsigned __loop_id_; |
| 1463 | bool __greedy_; |
| 1464 | |
| 1465 | public: |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame^] | 1466 | typedef _STD::__command<_CharT> __command; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1467 | |
| 1468 | explicit __loop(unsigned __loop_id, |
| 1469 | __state<_CharT>* __s1, __owns_one_state<_CharT>* __s2, |
| 1470 | bool __greedy = true, |
| 1471 | size_t __min = 0, |
| 1472 | size_t __max = numeric_limits<size_t>::max()) |
| 1473 | : base(__s1, __s2), __min_(__min), __max_(__max), __loop_id_(__loop_id), |
| 1474 | __greedy_(__greedy) {} |
| 1475 | |
| 1476 | virtual __command __test(const _CharT* __first, const _CharT* __current, |
| 1477 | const _CharT* __last, |
| 1478 | vector<size_t>&, |
| 1479 | sub_match<const _CharT*>*, |
| 1480 | regex_constants::match_flag_type __flags) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1481 | |
| 1482 | virtual string speak() const |
| 1483 | { |
| 1484 | ostringstream os; |
| 1485 | os << "loop {" << __min_ << ',' << __max_ << "}"; |
| 1486 | if (!__greedy_) |
| 1487 | os << " not"; |
| 1488 | os << " greedy"; |
| 1489 | return os.str(); |
| 1490 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1491 | }; |
| 1492 | |
| 1493 | template <class _CharT> |
| 1494 | __command<_CharT> |
| 1495 | __loop<_CharT>::__test(const _CharT* __first, const _CharT* __current, |
| 1496 | const _CharT* __last, |
| 1497 | vector<size_t>& __lc, |
| 1498 | sub_match<const _CharT*>* __m, |
| 1499 | regex_constants::match_flag_type __flags) const |
| 1500 | { |
| 1501 | size_t __count = __lc[__loop_id_]; |
| 1502 | if (__min_ <= __count && __count < __max_) |
| 1503 | if (__greedy_) |
| 1504 | return __command(__command::__accept_but_not_consume, this->first(), |
| 1505 | this->second()); |
| 1506 | else |
| 1507 | return __command(__command::__accept_but_not_consume, this->second(), |
| 1508 | this->first()); |
| 1509 | if (__min_ <= __count) |
| 1510 | return __command(__command::__accept_but_not_consume, this->second()); |
| 1511 | if (__count < __max_) |
| 1512 | return __command(__command::__accept_but_not_consume, this->first()); |
| 1513 | throw regex_error(regex_constants::error_temp); |
| 1514 | } |
| 1515 | |
| 1516 | // __zero_loop_count |
| 1517 | |
| 1518 | template <class _CharT> |
| 1519 | class __zero_loop_count |
| 1520 | : public __owns_one_state<_CharT> |
| 1521 | { |
| 1522 | typedef __owns_one_state<_CharT> base; |
| 1523 | |
| 1524 | size_t __loop_id_; |
| 1525 | |
| 1526 | public: |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame^] | 1527 | typedef _STD::__command<_CharT> __command; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1528 | |
| 1529 | explicit __zero_loop_count(size_t __loop_id, |
| 1530 | __state<_CharT>* __s1) |
| 1531 | : base(__s1), __loop_id_(__loop_id) {} |
| 1532 | |
| 1533 | virtual __command __test(const _CharT*, const _CharT*, const _CharT*, |
| 1534 | vector<size_t>& __lc, |
| 1535 | sub_match<const _CharT*>*, |
| 1536 | regex_constants::match_flag_type) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1537 | |
| 1538 | virtual string speak() const |
| 1539 | { |
| 1540 | ostringstream os; |
| 1541 | os << "zero loop " << __loop_id_; |
| 1542 | return os.str(); |
| 1543 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1544 | }; |
| 1545 | |
| 1546 | template <class _CharT> |
| 1547 | __command<_CharT> |
| 1548 | __zero_loop_count<_CharT>::__test(const _CharT*, const _CharT*, const _CharT*, |
| 1549 | vector<size_t>& __lc, |
| 1550 | sub_match<const _CharT*>*, |
| 1551 | regex_constants::match_flag_type) const |
| 1552 | { |
| 1553 | __lc[__loop_id_] = 0; |
| 1554 | return __command(__command::__accept_but_not_consume, this->first()); |
| 1555 | } |
| 1556 | |
| 1557 | // __increment_loop_count |
| 1558 | |
| 1559 | template <class _CharT> |
| 1560 | class __increment_loop_count |
| 1561 | : public __has_one_state<_CharT> |
| 1562 | { |
| 1563 | typedef __has_one_state<_CharT> base; |
| 1564 | |
| 1565 | size_t __loop_id_; |
| 1566 | |
| 1567 | public: |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame^] | 1568 | typedef _STD::__command<_CharT> __command; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1569 | |
| 1570 | explicit __increment_loop_count(size_t __loop_id, |
| 1571 | __state<_CharT>* __s1) |
| 1572 | : base(__s1), __loop_id_(__loop_id) {} |
| 1573 | |
| 1574 | virtual __command __test(const _CharT*, const _CharT*, const _CharT*, |
| 1575 | vector<size_t>& __lc, |
| 1576 | sub_match<const _CharT*>*, |
| 1577 | regex_constants::match_flag_type) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1578 | |
| 1579 | virtual string speak() const |
| 1580 | { |
| 1581 | ostringstream os; |
| 1582 | os << "increment loop " << __loop_id_; |
| 1583 | return os.str(); |
| 1584 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1585 | }; |
| 1586 | |
| 1587 | template <class _CharT> |
| 1588 | __command<_CharT> |
| 1589 | __increment_loop_count<_CharT>::__test(const _CharT*, const _CharT*, const _CharT*, |
| 1590 | vector<size_t>& __lc, |
| 1591 | sub_match<const _CharT*>*, |
| 1592 | regex_constants::match_flag_type) const |
| 1593 | { |
| 1594 | ++__lc[__loop_id_]; |
| 1595 | return __command(__command::__accept_but_not_consume, this->first()); |
| 1596 | } |
| 1597 | |
| 1598 | // __zero_marked_exprs |
| 1599 | |
| 1600 | template <class _CharT> |
| 1601 | class __zero_marked_exprs |
| 1602 | : public __owns_one_state<_CharT> |
| 1603 | { |
| 1604 | typedef __owns_one_state<_CharT> base; |
| 1605 | |
| 1606 | size_t __begin_; |
| 1607 | size_t __end_; |
| 1608 | |
| 1609 | public: |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame^] | 1610 | typedef _STD::__command<_CharT> __command; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1611 | |
| 1612 | explicit __zero_marked_exprs(size_t __begin, size_t __end, |
| 1613 | __state<_CharT>* __s1) |
| 1614 | : base(__s1), __begin_(__begin), __end_(__end) {} |
| 1615 | |
| 1616 | virtual __command __test(const _CharT*, const _CharT*, const _CharT*, |
| 1617 | vector<size_t>&, |
| 1618 | sub_match<const _CharT*>* __sm, |
| 1619 | regex_constants::match_flag_type) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1620 | |
| 1621 | virtual string speak() const |
| 1622 | { |
| 1623 | ostringstream os; |
| 1624 | os << "zero marked exprs [" << __begin_ << ',' << __end_ << ')'; |
| 1625 | return os.str(); |
| 1626 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1627 | }; |
| 1628 | |
| 1629 | template <class _CharT> |
| 1630 | __command<_CharT> |
| 1631 | __zero_marked_exprs<_CharT>::__test(const _CharT*, const _CharT*, |
| 1632 | const _CharT* __last, |
| 1633 | vector<size_t>&, |
| 1634 | sub_match<const _CharT*>* __sm, |
| 1635 | regex_constants::match_flag_type) const |
| 1636 | { |
| 1637 | for (size_t __i = __begin_; __i != __end_; ++__i) |
| 1638 | { |
| 1639 | __sm[__i].first = __last; |
| 1640 | __sm[__i].second = __last; |
| 1641 | __sm[__i].matched = false; |
| 1642 | } |
| 1643 | return __command(__command::__accept_but_not_consume, this->first()); |
| 1644 | } |
| 1645 | |
| 1646 | // __begin_marked_subexpression |
| 1647 | |
| 1648 | template <class _CharT> |
| 1649 | class __begin_marked_subexpression |
| 1650 | : public __owns_one_state<_CharT> |
| 1651 | { |
| 1652 | typedef __owns_one_state<_CharT> base; |
| 1653 | |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1654 | unsigned __mexp_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1655 | public: |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame^] | 1656 | typedef _STD::__command<_CharT> __command; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1657 | |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1658 | explicit __begin_marked_subexpression(unsigned __mexp, __state<_CharT>* __s) |
| 1659 | : base(__s), __mexp_(__mexp) {} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1660 | |
| 1661 | virtual __command __test(const _CharT*, const _CharT*, |
| 1662 | const _CharT*, |
| 1663 | vector<size_t>&, |
| 1664 | sub_match<const _CharT*>*, |
| 1665 | regex_constants::match_flag_type) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1666 | |
| 1667 | virtual string speak() const |
| 1668 | { |
| 1669 | ostringstream os; |
| 1670 | os << "begin marked expr " << __mexp_; |
| 1671 | return os.str(); |
| 1672 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1673 | }; |
| 1674 | |
| 1675 | template <class _CharT> |
| 1676 | __command<_CharT> |
| 1677 | __begin_marked_subexpression<_CharT>::__test(const _CharT*, const _CharT* __c, const _CharT*, |
| 1678 | vector<size_t>&, |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1679 | sub_match<const _CharT*>* __s, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1680 | regex_constants::match_flag_type) const |
| 1681 | { |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1682 | __s[__mexp_].first = __c; |
| 1683 | return __command(__command::__accept_but_not_consume, this->first()); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1684 | } |
| 1685 | |
| 1686 | // __end_marked_subexpression |
| 1687 | |
| 1688 | template <class _CharT> |
| 1689 | class __end_marked_subexpression |
| 1690 | : public __owns_one_state<_CharT> |
| 1691 | { |
| 1692 | typedef __owns_one_state<_CharT> base; |
| 1693 | |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1694 | unsigned __mexp_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1695 | public: |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame^] | 1696 | typedef _STD::__command<_CharT> __command; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1697 | |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1698 | explicit __end_marked_subexpression(unsigned __mexp, __state<_CharT>* __s) |
| 1699 | : base(__s), __mexp_(__mexp) {} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1700 | |
| 1701 | virtual __command __test(const _CharT*, const _CharT*, |
| 1702 | const _CharT*, |
| 1703 | vector<size_t>&, |
| 1704 | sub_match<const _CharT*>*, |
| 1705 | regex_constants::match_flag_type) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1706 | |
| 1707 | virtual string speak() const |
| 1708 | { |
| 1709 | ostringstream os; |
| 1710 | os << "end marked expr " << __mexp_; |
| 1711 | return os.str(); |
| 1712 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1713 | }; |
| 1714 | |
| 1715 | template <class _CharT> |
| 1716 | __command<_CharT> |
| 1717 | __end_marked_subexpression<_CharT>::__test(const _CharT*, const _CharT* __c, const _CharT*, |
| 1718 | vector<size_t>&, |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1719 | sub_match<const _CharT*>* __s, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1720 | regex_constants::match_flag_type) const |
| 1721 | { |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1722 | __s[__mexp_].second = __c; |
| 1723 | __s[__mexp_].matched = true; |
| 1724 | return __command(__command::__accept_but_not_consume, this->first()); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1725 | } |
| 1726 | |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame^] | 1727 | // __r_anchor |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1728 | |
| 1729 | template <class _CharT> |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame^] | 1730 | class __r_anchor |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1731 | : public __owns_one_state<_CharT> |
| 1732 | { |
| 1733 | typedef __owns_one_state<_CharT> base; |
| 1734 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1735 | public: |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame^] | 1736 | typedef _STD::__command<_CharT> __command; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1737 | |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame^] | 1738 | __r_anchor(__state<_CharT>* __s) |
| 1739 | : base(__s) {} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1740 | |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame^] | 1741 | virtual __command __test(const _CharT*, const _CharT* __c, |
| 1742 | const _CharT* __l, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1743 | vector<size_t>&, |
| 1744 | sub_match<const _CharT*>*, |
| 1745 | regex_constants::match_flag_type) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1746 | |
| 1747 | virtual string speak() const |
| 1748 | { |
| 1749 | ostringstream os; |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame^] | 1750 | os << "right anchor"; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1751 | return os.str(); |
| 1752 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1753 | }; |
| 1754 | |
| 1755 | template <class _CharT> |
| 1756 | __command<_CharT> |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame^] | 1757 | __r_anchor<_CharT>::__test(const _CharT*, const _CharT* __c, const _CharT* __l, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1758 | vector<size_t>&, |
| 1759 | sub_match<const _CharT*>*, |
| 1760 | regex_constants::match_flag_type) const |
| 1761 | { |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame^] | 1762 | return __c == __l ? |
| 1763 | __command(__command::__accept_but_not_consume, this->first()) : __command(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1764 | } |
| 1765 | |
| 1766 | // __match_char |
| 1767 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1768 | template <class _CharT> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1769 | class __match_char |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1770 | : public __owns_one_state<_CharT> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1771 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1772 | typedef __owns_one_state<_CharT> base; |
| 1773 | |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1774 | _CharT __c_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1775 | |
| 1776 | __match_char(const __match_char&); |
| 1777 | __match_char& operator=(const __match_char&); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1778 | public: |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame^] | 1779 | typedef _STD::__command<_CharT> __command; |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1780 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1781 | __match_char(_CharT __c, __state<_CharT>* __s) |
| 1782 | : base(__s), __c_(__c) {} |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1783 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1784 | virtual __command __test(const _CharT*, const _CharT* __c, |
| 1785 | const _CharT*, |
| 1786 | vector<size_t>&, |
| 1787 | sub_match<const _CharT*>*, |
| 1788 | regex_constants::match_flag_type) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1789 | |
| 1790 | virtual string speak() const |
| 1791 | { |
| 1792 | ostringstream os; |
| 1793 | os << "match char " << __c_; |
| 1794 | return os.str(); |
| 1795 | } |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1796 | }; |
| 1797 | |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1798 | template <class _CharT> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1799 | __command<_CharT> |
| 1800 | __match_char<_CharT>::__test(const _CharT*, const _CharT* __c, |
| 1801 | const _CharT*, |
| 1802 | vector<size_t>&, |
| 1803 | sub_match<const _CharT*>*, |
| 1804 | regex_constants::match_flag_type) const |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1805 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1806 | return __c_ == *__c ? |
| 1807 | __command(__command::__accept_and_consume, this->first()) : __command(); |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1808 | } |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1809 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1810 | template <class, class> class match_results; |
| 1811 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 1812 | template <class _CharT, class _Traits = regex_traits<_CharT> > |
| 1813 | class basic_regex |
| 1814 | { |
| 1815 | public: |
| 1816 | // types: |
| 1817 | typedef _CharT value_type; |
| 1818 | typedef regex_constants::syntax_option_type flag_type; |
| 1819 | typedef typename _Traits::locale_type locale_type; |
| 1820 | |
| 1821 | private: |
| 1822 | _Traits __traits_; |
| 1823 | flag_type __flags_; |
| 1824 | unsigned __marked_count_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1825 | unsigned __loop_count_; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1826 | int __open_count_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1827 | shared_ptr<__empty_state<_CharT> > __start_; |
| 1828 | __owns_one_state<_CharT>* __end_; |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame^] | 1829 | bool __left_anchor_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1830 | |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame^] | 1831 | typedef _STD::__command<_CharT> __command; |
| 1832 | typedef _STD::__state<_CharT> __state; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 1833 | |
| 1834 | public: |
| 1835 | // constants: |
| 1836 | static const/*expr*/ regex_constants::syntax_option_type icase = regex_constants::icase; |
| 1837 | static const/*expr*/ regex_constants::syntax_option_type nosubs = regex_constants::nosubs; |
| 1838 | static const/*expr*/ regex_constants::syntax_option_type optimize = regex_constants::optimize; |
| 1839 | static const/*expr*/ regex_constants::syntax_option_type collate = regex_constants::collate; |
| 1840 | static const/*expr*/ regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript; |
| 1841 | static const/*expr*/ regex_constants::syntax_option_type basic = regex_constants::basic; |
| 1842 | static const/*expr*/ regex_constants::syntax_option_type extended = regex_constants::extended; |
| 1843 | static const/*expr*/ regex_constants::syntax_option_type awk = regex_constants::awk; |
| 1844 | static const/*expr*/ regex_constants::syntax_option_type grep = regex_constants::grep; |
| 1845 | static const/*expr*/ regex_constants::syntax_option_type egrep = regex_constants::egrep; |
| 1846 | |
| 1847 | // construct/copy/destroy: |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1848 | basic_regex() |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame^] | 1849 | : __flags_(), __marked_count_(0), __loop_count_(0), __open_count_(0), |
| 1850 | __end_(0), __left_anchor_(false) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1851 | {} |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 1852 | 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^] | 1853 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
| 1854 | __end_(0), __left_anchor_(false) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 1855 | {__parse(__p, __p + __traits_.length(__p));} |
| 1856 | basic_regex(const value_type* __p, size_t __len, flag_type __f) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame^] | 1857 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
| 1858 | __end_(0), __left_anchor_(false) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 1859 | {__parse(__p, __p + __len);} |
| 1860 | basic_regex(const basic_regex&); |
| 1861 | #ifdef _LIBCPP_MOVE |
| 1862 | basic_regex(basic_regex&&); |
| 1863 | #endif |
| 1864 | template <class _ST, class _SA> |
| 1865 | explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p, |
| 1866 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame^] | 1867 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
| 1868 | __end_(0), __left_anchor_(false) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 1869 | {__parse(__p.begin(), __p.end());} |
| 1870 | template <class _ForwardIterator> |
| 1871 | basic_regex(_ForwardIterator __first, _ForwardIterator __last, |
| 1872 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame^] | 1873 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
| 1874 | __end_(0), __left_anchor_(false) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 1875 | {__parse(__first, __last);} |
| 1876 | basic_regex(initializer_list<value_type> __il, |
| 1877 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame^] | 1878 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
| 1879 | __end_(0), __left_anchor_(false) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 1880 | {__parse(__il.begin(), __il.end());} |
| 1881 | |
| 1882 | ~basic_regex(); |
| 1883 | |
| 1884 | basic_regex& operator=(const basic_regex&); |
| 1885 | #ifdef _LIBCPP_MOVE |
| 1886 | basic_regex& operator=(basic_regex&&); |
| 1887 | #endif |
| 1888 | basic_regex& operator=(const value_type* __p); |
| 1889 | basic_regex& operator=(initializer_list<value_type> __il); |
| 1890 | template <class _ST, class _SA> |
| 1891 | basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p); |
| 1892 | |
| 1893 | // assign: |
| 1894 | basic_regex& assign(const basic_regex& __that); |
| 1895 | #ifdef _LIBCPP_MOVE |
| 1896 | basic_regex& assign(basic_regex&& __that); |
| 1897 | #endif |
| 1898 | basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript); |
| 1899 | basic_regex& assign(const value_type* __p, size_t __len, flag_type __f); |
| 1900 | template <class _ST, class _SA> |
| 1901 | basic_regex& assign(const basic_string<value_type, _ST, _SA>& __s, |
| 1902 | flag_type __f = regex_constants::ECMAScript); |
| 1903 | template <class _InputIterator> |
| 1904 | basic_regex& assign(_InputIterator __first, _InputIterator __last, |
| 1905 | flag_type __f = regex_constants::ECMAScript); |
| 1906 | basic_regex& assign(initializer_list<value_type> __il, |
| 1907 | flag_type = regex_constants::ECMAScript); |
| 1908 | |
| 1909 | // const operations: |
| 1910 | unsigned mark_count() const {return __marked_count_;} |
| 1911 | flag_type flags() const {return __flags_;} |
| 1912 | |
| 1913 | // locale: |
| 1914 | locale_type imbue(locale_type __loc) {return __traits_.imbue(__loc);} |
| 1915 | locale_type getloc() const {return __traits_.getloc();} |
| 1916 | |
| 1917 | // swap: |
| 1918 | void swap(basic_regex&); |
| 1919 | |
| 1920 | private: |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1921 | unsigned __loop_count() const {return __loop_count_;} |
| 1922 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 1923 | template <class _ForwardIterator> |
| 1924 | void __parse(_ForwardIterator __first, _ForwardIterator __last); |
| 1925 | template <class _ForwardIterator> |
| 1926 | _ForwardIterator |
| 1927 | __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 1928 | template <class _ForwardIterator> |
| 1929 | _ForwardIterator |
| 1930 | __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 1931 | template <class _ForwardIterator> |
| 1932 | _ForwardIterator |
| 1933 | __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 1934 | template <class _ForwardIterator> |
| 1935 | _ForwardIterator |
| 1936 | __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 1937 | template <class _ForwardIterator> |
| 1938 | _ForwardIterator |
| 1939 | __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 1940 | template <class _ForwardIterator> |
| 1941 | _ForwardIterator |
| 1942 | __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last); |
| 1943 | template <class _ForwardIterator> |
| 1944 | _ForwardIterator |
| 1945 | __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last); |
| 1946 | template <class _ForwardIterator> |
| 1947 | _ForwardIterator |
| 1948 | __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last); |
| 1949 | template <class _ForwardIterator> |
| 1950 | _ForwardIterator |
| 1951 | __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last); |
| 1952 | template <class _ForwardIterator> |
| 1953 | _ForwardIterator |
| 1954 | __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last); |
| 1955 | template <class _ForwardIterator> |
| 1956 | _ForwardIterator |
| 1957 | __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last); |
| 1958 | template <class _ForwardIterator> |
| 1959 | _ForwardIterator |
| 1960 | __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last); |
| 1961 | template <class _ForwardIterator> |
| 1962 | _ForwardIterator |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1963 | __parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last, |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1964 | __owns_one_state<_CharT>* __s, |
| 1965 | unsigned __mexp_begin, unsigned __mexp_end); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 1966 | template <class _ForwardIterator> |
| 1967 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1968 | __parse_ERE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last); |
| 1969 | template <class _ForwardIterator> |
| 1970 | _ForwardIterator |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 1971 | __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 1972 | template <class _ForwardIterator> |
| 1973 | _ForwardIterator |
| 1974 | __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last); |
| 1975 | template <class _ForwardIterator> |
| 1976 | _ForwardIterator |
| 1977 | __parse_expression_term(_ForwardIterator __first, _ForwardIterator __last); |
| 1978 | template <class _ForwardIterator> |
| 1979 | _ForwardIterator |
| 1980 | __parse_equivalence_class(_ForwardIterator __first, _ForwardIterator __last); |
| 1981 | template <class _ForwardIterator> |
| 1982 | _ForwardIterator |
| 1983 | __parse_character_class(_ForwardIterator __first, _ForwardIterator __last); |
| 1984 | template <class _ForwardIterator> |
| 1985 | _ForwardIterator |
| 1986 | __parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last); |
| 1987 | template <class _ForwardIterator> |
| 1988 | _ForwardIterator |
| 1989 | __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1990 | template <class _ForwardIterator> |
| 1991 | _ForwardIterator |
| 1992 | __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 1993 | template <class _ForwardIterator> |
| 1994 | _ForwardIterator |
| 1995 | __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last); |
| 1996 | template <class _ForwardIterator> |
| 1997 | _ForwardIterator |
| 1998 | __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 1999 | template <class _ForwardIterator> |
| 2000 | _ForwardIterator |
| 2001 | __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last); |
| 2002 | template <class _ForwardIterator> |
| 2003 | _ForwardIterator |
| 2004 | __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last); |
| 2005 | template <class _ForwardIterator> |
| 2006 | _ForwardIterator |
| 2007 | __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2008 | |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame^] | 2009 | void __push_l_anchor() {__left_anchor_ = true;} |
| 2010 | void __push_r_anchor(); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2011 | void __push_match_any() {} |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2012 | void __push_greedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s, |
| 2013 | unsigned __mexp_begin = 0, unsigned __mexp_end = 0) |
| 2014 | {__push_loop(__min, numeric_limits<size_t>::max(), __s, |
| 2015 | __mexp_begin, __mexp_end);} |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2016 | void __push_exact_repeat(int __count) {} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2017 | void __push_loop(size_t __min, size_t __max, __owns_one_state<_CharT>* __s, |
| 2018 | size_t __mexp_begin = 0, size_t __mexp_end = 0, |
| 2019 | bool __greedy = true); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2020 | void __start_nonmatching_list() {} |
| 2021 | void __start_matching_list() {} |
| 2022 | void __end_nonmatching_list() {} |
| 2023 | void __end_matching_list() {} |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2024 | void __push_char(value_type __c); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2025 | void __push_char(const typename _Traits::string_type& __c) {} |
| 2026 | void __push_range() {} |
| 2027 | void __push_class_type(typename _Traits::char_class_type) {} |
| 2028 | void __push_back_ref(int __i) {} |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2029 | void __push_alternation() {} |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2030 | void __push_begin_marked_subexpression(); |
| 2031 | void __push_end_marked_subexpression(unsigned); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2032 | |
| 2033 | template <class _BidirectionalIterator, class _Allocator> |
| 2034 | bool |
| 2035 | __search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 2036 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 2037 | regex_constants::match_flag_type __flags) const; |
| 2038 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2039 | template <class _BidirectionalIterator, class _Allocator> |
| 2040 | bool |
| 2041 | __match_at_start(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 2042 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 2043 | vector<size_t>& __lc, |
| 2044 | regex_constants::match_flag_type __flags) const; |
| 2045 | template <class _BidirectionalIterator, class _Allocator> |
| 2046 | bool |
| 2047 | __match_at_start_ecma(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 2048 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 2049 | regex_constants::match_flag_type __flags) const; |
| 2050 | template <class _BidirectionalIterator, class _Allocator> |
| 2051 | bool |
| 2052 | __match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last, |
| 2053 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 2054 | vector<size_t>& __lc, |
| 2055 | regex_constants::match_flag_type __flags) const; |
| 2056 | template <class _BidirectionalIterator, class _Allocator> |
| 2057 | bool |
| 2058 | __match_at_start_posix_subs(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 2059 | match_results<_BidirectionalIterator, _Allocator>& __m, |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2060 | vector<size_t>& __lc, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2061 | regex_constants::match_flag_type __flags) const; |
| 2062 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2063 | template <class _B, class _A, class _C, class _T> |
| 2064 | friend |
| 2065 | bool |
| 2066 | regex_search(_B, _B, match_results<_B, _A>&, const basic_regex<_C, _T>&, |
| 2067 | regex_constants::match_flag_type); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2068 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2069 | }; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2070 | |
| 2071 | template <class _CharT, class _Traits> |
| 2072 | basic_regex<_CharT, _Traits>::~basic_regex() |
| 2073 | { |
| 2074 | } |
| 2075 | |
| 2076 | template <class _CharT, class _Traits> |
| 2077 | template <class _ForwardIterator> |
| 2078 | void |
| 2079 | basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first, |
| 2080 | _ForwardIterator __last) |
| 2081 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2082 | { |
| 2083 | unique_ptr<__state> __h(new __end_state<_CharT>); |
| 2084 | __start_.reset(new __empty_state<_CharT>(__h.get())); |
| 2085 | __h.release(); |
| 2086 | __end_ = __start_.get(); |
| 2087 | } |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2088 | switch (__flags_ & 0x3F0) |
| 2089 | { |
| 2090 | case ECMAScript: |
| 2091 | break; |
| 2092 | case basic: |
| 2093 | __parse_basic_reg_exp(__first, __last); |
| 2094 | break; |
| 2095 | case extended: |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2096 | __parse_extended_reg_exp(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2097 | break; |
| 2098 | case awk: |
| 2099 | break; |
| 2100 | case grep: |
| 2101 | break; |
| 2102 | case egrep: |
| 2103 | break; |
| 2104 | default: |
| 2105 | throw regex_error(regex_constants::error_temp); |
| 2106 | } |
| 2107 | } |
| 2108 | |
| 2109 | template <class _CharT, class _Traits> |
| 2110 | template <class _ForwardIterator> |
| 2111 | _ForwardIterator |
| 2112 | basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first, |
| 2113 | _ForwardIterator __last) |
| 2114 | { |
| 2115 | if (__first != __last) |
| 2116 | { |
| 2117 | if (*__first == '^') |
| 2118 | { |
| 2119 | __push_l_anchor(); |
| 2120 | ++__first; |
| 2121 | } |
| 2122 | if (__first != __last) |
| 2123 | { |
| 2124 | __first = __parse_RE_expression(__first, __last); |
| 2125 | if (__first != __last) |
| 2126 | { |
| 2127 | _ForwardIterator __temp = next(__first); |
| 2128 | if (__temp == __last && *__first == '$') |
| 2129 | { |
| 2130 | __push_r_anchor(); |
| 2131 | ++__first; |
| 2132 | } |
| 2133 | } |
| 2134 | } |
| 2135 | if (__first != __last) |
| 2136 | throw regex_error(regex_constants::error_temp); |
| 2137 | } |
| 2138 | return __first; |
| 2139 | } |
| 2140 | |
| 2141 | template <class _CharT, class _Traits> |
| 2142 | template <class _ForwardIterator> |
| 2143 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2144 | basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first, |
| 2145 | _ForwardIterator __last) |
| 2146 | { |
| 2147 | while (true) |
| 2148 | { |
| 2149 | _ForwardIterator __temp = __parse_ERE_branch(__first, __last); |
| 2150 | if (__temp == __first) |
| 2151 | throw regex_error(regex_constants::error_temp); |
| 2152 | __first = __temp; |
| 2153 | if (__first == __last) |
| 2154 | break; |
| 2155 | if (*__first != '|') |
| 2156 | throw regex_error(regex_constants::error_temp); |
| 2157 | __push_alternation(); |
| 2158 | ++__first; |
| 2159 | } |
| 2160 | return __first; |
| 2161 | } |
| 2162 | |
| 2163 | template <class _CharT, class _Traits> |
| 2164 | template <class _ForwardIterator> |
| 2165 | _ForwardIterator |
| 2166 | basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first, |
| 2167 | _ForwardIterator __last) |
| 2168 | { |
| 2169 | _ForwardIterator __temp = __parse_ERE_expression(__first, __last); |
| 2170 | if (__temp == __first) |
| 2171 | throw regex_error(regex_constants::error_temp); |
| 2172 | do |
| 2173 | { |
| 2174 | __first = __temp; |
| 2175 | __temp = __parse_ERE_expression(__first, __last); |
| 2176 | } while (__temp != __first); |
| 2177 | return __first; |
| 2178 | } |
| 2179 | |
| 2180 | template <class _CharT, class _Traits> |
| 2181 | template <class _ForwardIterator> |
| 2182 | _ForwardIterator |
| 2183 | basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first, |
| 2184 | _ForwardIterator __last) |
| 2185 | { |
| 2186 | _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last); |
| 2187 | if (__temp == __first && __temp != __last) |
| 2188 | { |
| 2189 | switch (*__temp) |
| 2190 | { |
| 2191 | case '^': |
| 2192 | __push_l_anchor(); |
| 2193 | ++__temp; |
| 2194 | break; |
| 2195 | case '$': |
| 2196 | __push_r_anchor(); |
| 2197 | ++__temp; |
| 2198 | break; |
| 2199 | case '(': |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2200 | __push_begin_marked_subexpression(); |
| 2201 | unsigned __temp_count = __marked_count_; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2202 | ++__open_count_; |
| 2203 | __temp = __parse_extended_reg_exp(++__temp, __last); |
| 2204 | if (__temp == __last || *__temp != ')') |
| 2205 | throw regex_error(regex_constants::error_paren); |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2206 | __push_end_marked_subexpression(__temp_count); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2207 | --__open_count_; |
| 2208 | ++__temp; |
| 2209 | break; |
| 2210 | } |
| 2211 | } |
| 2212 | if (__temp != __first) |
| 2213 | __temp = __parse_ERE_dupl_symbol(__temp, __last); |
| 2214 | __first = __temp; |
| 2215 | return __first; |
| 2216 | } |
| 2217 | |
| 2218 | template <class _CharT, class _Traits> |
| 2219 | template <class _ForwardIterator> |
| 2220 | _ForwardIterator |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2221 | basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first, |
| 2222 | _ForwardIterator __last) |
| 2223 | { |
| 2224 | while (true) |
| 2225 | { |
| 2226 | _ForwardIterator __temp = __parse_simple_RE(__first, __last); |
| 2227 | if (__temp == __first) |
| 2228 | break; |
| 2229 | __first = __temp; |
| 2230 | } |
| 2231 | return __first; |
| 2232 | } |
| 2233 | |
| 2234 | template <class _CharT, class _Traits> |
| 2235 | template <class _ForwardIterator> |
| 2236 | _ForwardIterator |
| 2237 | basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first, |
| 2238 | _ForwardIterator __last) |
| 2239 | { |
| 2240 | if (__first != __last) |
| 2241 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2242 | __owns_one_state<_CharT>* __e = __end_; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2243 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2244 | _ForwardIterator __temp = __parse_nondupl_RE(__first, __last); |
| 2245 | if (__temp != __first) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2246 | __first = __parse_RE_dupl_symbol(__temp, __last, __e, |
| 2247 | __mexp_begin+1, __marked_count_+1); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2248 | } |
| 2249 | return __first; |
| 2250 | } |
| 2251 | |
| 2252 | template <class _CharT, class _Traits> |
| 2253 | template <class _ForwardIterator> |
| 2254 | _ForwardIterator |
| 2255 | basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first, |
| 2256 | _ForwardIterator __last) |
| 2257 | { |
| 2258 | _ForwardIterator __temp = __first; |
| 2259 | __first = __parse_one_char_or_coll_elem_RE(__first, __last); |
| 2260 | if (__temp == __first) |
| 2261 | { |
| 2262 | __temp = __parse_Back_open_paren(__first, __last); |
| 2263 | if (__temp != __first) |
| 2264 | { |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2265 | __push_begin_marked_subexpression(); |
| 2266 | unsigned __temp_count = __marked_count_; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2267 | __first = __parse_RE_expression(__temp, __last); |
| 2268 | __temp = __parse_Back_close_paren(__first, __last); |
| 2269 | if (__temp == __first) |
| 2270 | throw regex_error(regex_constants::error_paren); |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2271 | __push_end_marked_subexpression(__temp_count); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2272 | __first = __temp; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2273 | } |
| 2274 | else |
| 2275 | __first = __parse_BACKREF(__first, __last); |
| 2276 | } |
| 2277 | return __first; |
| 2278 | } |
| 2279 | |
| 2280 | template <class _CharT, class _Traits> |
| 2281 | template <class _ForwardIterator> |
| 2282 | _ForwardIterator |
| 2283 | basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE( |
| 2284 | _ForwardIterator __first, |
| 2285 | _ForwardIterator __last) |
| 2286 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2287 | _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2288 | if (__temp == __first) |
| 2289 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2290 | __temp = __parse_QUOTED_CHAR(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2291 | if (__temp == __first) |
| 2292 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2293 | if (__temp != __last && *__temp == '.') |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2294 | { |
| 2295 | __push_match_any(); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2296 | ++__temp; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2297 | } |
| 2298 | else |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2299 | __temp = __parse_bracket_expression(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2300 | } |
| 2301 | } |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2302 | __first = __temp; |
| 2303 | return __first; |
| 2304 | } |
| 2305 | |
| 2306 | template <class _CharT, class _Traits> |
| 2307 | template <class _ForwardIterator> |
| 2308 | _ForwardIterator |
| 2309 | basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE( |
| 2310 | _ForwardIterator __first, |
| 2311 | _ForwardIterator __last) |
| 2312 | { |
| 2313 | _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last); |
| 2314 | if (__temp == __first) |
| 2315 | { |
| 2316 | __temp = __parse_QUOTED_CHAR_ERE(__first, __last); |
| 2317 | if (__temp == __first) |
| 2318 | { |
| 2319 | if (__temp != __last && *__temp == '.') |
| 2320 | { |
| 2321 | __push_match_any(); |
| 2322 | ++__temp; |
| 2323 | } |
| 2324 | else |
| 2325 | __temp = __parse_bracket_expression(__first, __last); |
| 2326 | } |
| 2327 | } |
| 2328 | __first = __temp; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2329 | return __first; |
| 2330 | } |
| 2331 | |
| 2332 | template <class _CharT, class _Traits> |
| 2333 | template <class _ForwardIterator> |
| 2334 | _ForwardIterator |
| 2335 | basic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first, |
| 2336 | _ForwardIterator __last) |
| 2337 | { |
| 2338 | if (__first != __last) |
| 2339 | { |
| 2340 | _ForwardIterator __temp = next(__first); |
| 2341 | if (__temp != __last) |
| 2342 | { |
| 2343 | if (*__first == '\\' && *__temp == '(') |
| 2344 | __first = ++__temp; |
| 2345 | } |
| 2346 | } |
| 2347 | return __first; |
| 2348 | } |
| 2349 | |
| 2350 | template <class _CharT, class _Traits> |
| 2351 | template <class _ForwardIterator> |
| 2352 | _ForwardIterator |
| 2353 | basic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first, |
| 2354 | _ForwardIterator __last) |
| 2355 | { |
| 2356 | if (__first != __last) |
| 2357 | { |
| 2358 | _ForwardIterator __temp = next(__first); |
| 2359 | if (__temp != __last) |
| 2360 | { |
| 2361 | if (*__first == '\\' && *__temp == ')') |
| 2362 | __first = ++__temp; |
| 2363 | } |
| 2364 | } |
| 2365 | return __first; |
| 2366 | } |
| 2367 | |
| 2368 | template <class _CharT, class _Traits> |
| 2369 | template <class _ForwardIterator> |
| 2370 | _ForwardIterator |
| 2371 | basic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first, |
| 2372 | _ForwardIterator __last) |
| 2373 | { |
| 2374 | if (__first != __last) |
| 2375 | { |
| 2376 | _ForwardIterator __temp = next(__first); |
| 2377 | if (__temp != __last) |
| 2378 | { |
| 2379 | if (*__first == '\\' && *__temp == '{') |
| 2380 | __first = ++__temp; |
| 2381 | } |
| 2382 | } |
| 2383 | return __first; |
| 2384 | } |
| 2385 | |
| 2386 | template <class _CharT, class _Traits> |
| 2387 | template <class _ForwardIterator> |
| 2388 | _ForwardIterator |
| 2389 | basic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first, |
| 2390 | _ForwardIterator __last) |
| 2391 | { |
| 2392 | if (__first != __last) |
| 2393 | { |
| 2394 | _ForwardIterator __temp = next(__first); |
| 2395 | if (__temp != __last) |
| 2396 | { |
| 2397 | if (*__first == '\\' && *__temp == '}') |
| 2398 | __first = ++__temp; |
| 2399 | } |
| 2400 | } |
| 2401 | return __first; |
| 2402 | } |
| 2403 | |
| 2404 | template <class _CharT, class _Traits> |
| 2405 | template <class _ForwardIterator> |
| 2406 | _ForwardIterator |
| 2407 | basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first, |
| 2408 | _ForwardIterator __last) |
| 2409 | { |
| 2410 | if (__first != __last) |
| 2411 | { |
| 2412 | _ForwardIterator __temp = next(__first); |
| 2413 | if (__temp != __last) |
| 2414 | { |
| 2415 | if (*__first == '\\' && '1' <= *__temp && *__temp <= '9') |
| 2416 | { |
| 2417 | __push_back_ref(*__temp - '0'); |
| 2418 | __first = ++__temp; |
| 2419 | } |
| 2420 | } |
| 2421 | } |
| 2422 | return __first; |
| 2423 | } |
| 2424 | |
| 2425 | template <class _CharT, class _Traits> |
| 2426 | template <class _ForwardIterator> |
| 2427 | _ForwardIterator |
| 2428 | basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first, |
| 2429 | _ForwardIterator __last) |
| 2430 | { |
| 2431 | if (__first != __last) |
| 2432 | { |
| 2433 | _ForwardIterator __temp = next(__first); |
| 2434 | if (__temp == __last && *__first == '$') |
| 2435 | return __first; |
| 2436 | // Not called inside a bracket |
| 2437 | if (*__first == '.' || *__first == '\\' || *__first == '[') |
| 2438 | return __first; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2439 | __push_char(*__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2440 | ++__first; |
| 2441 | } |
| 2442 | return __first; |
| 2443 | } |
| 2444 | |
| 2445 | template <class _CharT, class _Traits> |
| 2446 | template <class _ForwardIterator> |
| 2447 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2448 | basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first, |
| 2449 | _ForwardIterator __last) |
| 2450 | { |
| 2451 | if (__first != __last) |
| 2452 | { |
| 2453 | switch (*__first) |
| 2454 | { |
| 2455 | case '^': |
| 2456 | case '.': |
| 2457 | case '[': |
| 2458 | case '$': |
| 2459 | case '(': |
| 2460 | case '|': |
| 2461 | case '*': |
| 2462 | case '+': |
| 2463 | case '?': |
| 2464 | case '{': |
| 2465 | case '\\': |
| 2466 | break; |
| 2467 | case ')': |
| 2468 | if (__open_count_ == 0) |
| 2469 | { |
| 2470 | __push_char(*__first); |
| 2471 | ++__first; |
| 2472 | } |
| 2473 | break; |
| 2474 | default: |
| 2475 | __push_char(*__first); |
| 2476 | ++__first; |
| 2477 | break; |
| 2478 | } |
| 2479 | } |
| 2480 | return __first; |
| 2481 | } |
| 2482 | |
| 2483 | template <class _CharT, class _Traits> |
| 2484 | template <class _ForwardIterator> |
| 2485 | _ForwardIterator |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2486 | basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first, |
| 2487 | _ForwardIterator __last) |
| 2488 | { |
| 2489 | if (__first != __last) |
| 2490 | { |
| 2491 | _ForwardIterator __temp = next(__first); |
| 2492 | if (__temp != __last) |
| 2493 | { |
| 2494 | if (*__first == '\\') |
| 2495 | { |
| 2496 | switch (*__temp) |
| 2497 | { |
| 2498 | case '^': |
| 2499 | case '.': |
| 2500 | case '*': |
| 2501 | case '[': |
| 2502 | case '$': |
| 2503 | case '\\': |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2504 | __push_char(*__temp); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2505 | __first = ++__temp; |
| 2506 | break; |
| 2507 | } |
| 2508 | } |
| 2509 | } |
| 2510 | } |
| 2511 | return __first; |
| 2512 | } |
| 2513 | |
| 2514 | template <class _CharT, class _Traits> |
| 2515 | template <class _ForwardIterator> |
| 2516 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2517 | basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first, |
| 2518 | _ForwardIterator __last) |
| 2519 | { |
| 2520 | if (__first != __last) |
| 2521 | { |
| 2522 | _ForwardIterator __temp = next(__first); |
| 2523 | if (__temp != __last) |
| 2524 | { |
| 2525 | if (*__first == '\\') |
| 2526 | { |
| 2527 | switch (*__temp) |
| 2528 | { |
| 2529 | case '^': |
| 2530 | case '.': |
| 2531 | case '*': |
| 2532 | case '[': |
| 2533 | case '$': |
| 2534 | case '\\': |
| 2535 | case '(': |
| 2536 | case ')': |
| 2537 | case '|': |
| 2538 | case '+': |
| 2539 | case '?': |
| 2540 | case '{': |
| 2541 | __push_char(*__temp); |
| 2542 | __first = ++__temp; |
| 2543 | break; |
| 2544 | } |
| 2545 | } |
| 2546 | } |
| 2547 | } |
| 2548 | return __first; |
| 2549 | } |
| 2550 | |
| 2551 | template <class _CharT, class _Traits> |
| 2552 | template <class _ForwardIterator> |
| 2553 | _ForwardIterator |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2554 | basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2555 | _ForwardIterator __last, |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2556 | __owns_one_state<_CharT>* __s, |
| 2557 | unsigned __mexp_begin, |
| 2558 | unsigned __mexp_end) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2559 | { |
| 2560 | if (__first != __last) |
| 2561 | { |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2562 | if (*__first == '*') |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2563 | { |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2564 | __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2565 | ++__first; |
| 2566 | } |
| 2567 | else |
| 2568 | { |
| 2569 | _ForwardIterator __temp = __parse_Back_open_brace(__first, __last); |
| 2570 | if (__temp != __first) |
| 2571 | { |
| 2572 | int __min = 0; |
| 2573 | __first = __temp; |
| 2574 | __temp = __parse_DUP_COUNT(__first, __last, __min); |
| 2575 | if (__temp == __first) |
| 2576 | throw regex_error(regex_constants::error_badbrace); |
| 2577 | __first = __temp; |
| 2578 | if (__first == __last) |
| 2579 | throw regex_error(regex_constants::error_brace); |
| 2580 | if (*__first != ',') |
| 2581 | { |
| 2582 | __temp = __parse_Back_close_brace(__first, __last); |
| 2583 | if (__temp == __first) |
| 2584 | throw regex_error(regex_constants::error_brace); |
| 2585 | __push_exact_repeat(__min); |
| 2586 | __first = __temp; |
| 2587 | } |
| 2588 | else |
| 2589 | { |
| 2590 | ++__first; // consume ',' |
| 2591 | int __max = -1; |
| 2592 | __first = __parse_DUP_COUNT(__first, __last, __max); |
| 2593 | __temp = __parse_Back_close_brace(__first, __last); |
| 2594 | if (__temp == __first) |
| 2595 | throw regex_error(regex_constants::error_brace); |
| 2596 | if (__max == -1) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2597 | __push_greedy_inf_repeat(__min, __s, __mexp_end, __mexp_end); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2598 | else |
| 2599 | { |
| 2600 | if (__max < __min) |
| 2601 | throw regex_error(regex_constants::error_badbrace); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2602 | __push_loop(__min, __max, __s); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2603 | } |
| 2604 | __first = __temp; |
| 2605 | } |
| 2606 | } |
| 2607 | } |
| 2608 | } |
| 2609 | return __first; |
| 2610 | } |
| 2611 | |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2612 | template <class _CharT, class _Traits> |
| 2613 | template <class _ForwardIterator> |
| 2614 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2615 | basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first, |
| 2616 | _ForwardIterator __last) |
| 2617 | { |
| 2618 | if (__first != __last) |
| 2619 | { |
| 2620 | switch (*__first) |
| 2621 | { |
| 2622 | case '*': |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2623 | __push_greedy_inf_repeat(0, nullptr); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2624 | ++__first; |
| 2625 | break; |
| 2626 | case '+': |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2627 | __push_greedy_inf_repeat(1, nullptr); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2628 | ++__first; |
| 2629 | break; |
| 2630 | case '?': |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2631 | __push_loop(0, 1, nullptr); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2632 | ++__first; |
| 2633 | break; |
| 2634 | case '{': |
| 2635 | { |
| 2636 | int __min; |
| 2637 | _ForwardIterator __temp = __parse_DUP_COUNT(__first, __last, __min); |
| 2638 | if (__temp == __first) |
| 2639 | throw regex_error(regex_constants::error_badbrace); |
| 2640 | __first = __temp; |
| 2641 | if (__first == __last) |
| 2642 | throw regex_error(regex_constants::error_brace); |
| 2643 | switch (*__first) |
| 2644 | { |
| 2645 | case '}': |
| 2646 | __push_exact_repeat(__min); |
| 2647 | ++__first; |
| 2648 | break; |
| 2649 | case ',': |
| 2650 | if (++__first == __last) |
| 2651 | throw regex_error(regex_constants::error_badbrace); |
| 2652 | if (*__first == '}') |
| 2653 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2654 | __push_greedy_inf_repeat(__min, nullptr); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2655 | ++__first; |
| 2656 | } |
| 2657 | else |
| 2658 | { |
| 2659 | int __max; |
| 2660 | __temp = __parse_DUP_COUNT(__first, __last, __max); |
| 2661 | if (__temp == __first) |
| 2662 | throw regex_error(regex_constants::error_brace); |
| 2663 | __first = __temp; |
| 2664 | if (__first == __last || *__first != '}') |
| 2665 | throw regex_error(regex_constants::error_brace); |
| 2666 | ++__first; |
| 2667 | if (__max < __min) |
| 2668 | throw regex_error(regex_constants::error_badbrace); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2669 | __push_loop(__min, __max, nullptr); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2670 | } |
| 2671 | default: |
| 2672 | throw regex_error(regex_constants::error_badbrace); |
| 2673 | } |
| 2674 | } |
| 2675 | break; |
| 2676 | } |
| 2677 | } |
| 2678 | return __first; |
| 2679 | } |
| 2680 | |
| 2681 | template <class _CharT, class _Traits> |
| 2682 | template <class _ForwardIterator> |
| 2683 | _ForwardIterator |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2684 | basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first, |
| 2685 | _ForwardIterator __last) |
| 2686 | { |
| 2687 | if (__first != __last && *__first == '[') |
| 2688 | { |
| 2689 | if (++__first == __last) |
| 2690 | throw regex_error(regex_constants::error_brack); |
| 2691 | bool __non_matching = false; |
| 2692 | if (*__first == '^') |
| 2693 | { |
| 2694 | ++__first; |
| 2695 | __non_matching = true; |
| 2696 | __start_nonmatching_list(); |
| 2697 | } |
| 2698 | else |
| 2699 | __start_matching_list(); |
| 2700 | if (__first == __last) |
| 2701 | throw regex_error(regex_constants::error_brack); |
| 2702 | if (*__first == ']') |
| 2703 | { |
| 2704 | __push_char(']'); |
| 2705 | ++__first; |
| 2706 | } |
| 2707 | __first = __parse_follow_list(__first, __last); |
| 2708 | if (__first == __last) |
| 2709 | throw regex_error(regex_constants::error_brack); |
| 2710 | if (*__first == '-') |
| 2711 | { |
| 2712 | __push_char('-'); |
| 2713 | ++__first; |
| 2714 | } |
| 2715 | if (__first == __last || *__first != ']') |
| 2716 | throw regex_error(regex_constants::error_brack); |
| 2717 | if (__non_matching) |
| 2718 | __end_nonmatching_list(); |
| 2719 | else |
| 2720 | __end_matching_list(); |
| 2721 | ++__first; |
| 2722 | } |
| 2723 | return __first; |
| 2724 | } |
| 2725 | |
| 2726 | template <class _CharT, class _Traits> |
| 2727 | template <class _ForwardIterator> |
| 2728 | _ForwardIterator |
| 2729 | basic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first, |
| 2730 | _ForwardIterator __last) |
| 2731 | { |
| 2732 | if (__first != __last) |
| 2733 | { |
| 2734 | while (true) |
| 2735 | { |
| 2736 | _ForwardIterator __temp = __parse_expression_term(__first, __last); |
| 2737 | if (__temp == __first) |
| 2738 | break; |
| 2739 | __first = __temp; |
| 2740 | } |
| 2741 | } |
| 2742 | return __first; |
| 2743 | } |
| 2744 | |
| 2745 | template <class _CharT, class _Traits> |
| 2746 | template <class _ForwardIterator> |
| 2747 | _ForwardIterator |
| 2748 | basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first, |
| 2749 | _ForwardIterator __last) |
| 2750 | { |
| 2751 | if (__first != __last && *__first != ']') |
| 2752 | { |
| 2753 | bool __parsed_one = false; |
| 2754 | _ForwardIterator __temp = next(__first); |
| 2755 | if (__temp != __last && *__first == '[') |
| 2756 | { |
| 2757 | if (*__temp == '=') |
| 2758 | return __parse_equivalence_class(++__temp, __last); |
| 2759 | else if (*__temp == ':') |
| 2760 | return __parse_character_class(++__temp, __last); |
| 2761 | else if (*__temp == '.') |
| 2762 | { |
| 2763 | __first = __parse_collating_symbol(++__temp, __last); |
| 2764 | __parsed_one = true; |
| 2765 | } |
| 2766 | } |
| 2767 | if (!__parsed_one) |
| 2768 | { |
| 2769 | __push_char(*__first); |
| 2770 | ++__first; |
| 2771 | } |
| 2772 | if (__first != __last && *__first != ']') |
| 2773 | { |
| 2774 | __temp = next(__first); |
| 2775 | if (__temp != __last && *__first == '-' && *__temp != ']') |
| 2776 | { |
| 2777 | // parse a range |
| 2778 | __first = __temp; |
| 2779 | ++__temp; |
| 2780 | if (__temp != __last && *__first == '[' && *__temp == '.') |
| 2781 | __first = __parse_collating_symbol(++__temp, __last); |
| 2782 | else |
| 2783 | { |
| 2784 | __push_char(*__first); |
| 2785 | ++__first; |
| 2786 | } |
| 2787 | __push_range(); |
| 2788 | } |
| 2789 | } |
| 2790 | } |
| 2791 | return __first; |
| 2792 | } |
| 2793 | |
| 2794 | template <class _CharT, class _Traits> |
| 2795 | template <class _ForwardIterator> |
| 2796 | _ForwardIterator |
| 2797 | basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first, |
| 2798 | _ForwardIterator __last) |
| 2799 | { |
| 2800 | // Found [= |
| 2801 | // This means =] must exist |
| 2802 | value_type _Equal_close[2] = {'=', ']'}; |
| 2803 | _ForwardIterator __temp = _STD::search(__first, __last, _Equal_close, |
| 2804 | _Equal_close+2); |
| 2805 | if (__temp == __last) |
| 2806 | throw regex_error(regex_constants::error_brack); |
| 2807 | // [__first, __temp) contains all text in [= ... =] |
| 2808 | typedef typename _Traits::string_type string_type; |
| 2809 | string_type __collate_name = |
| 2810 | __traits_.lookup_collatename(__first, __temp); |
| 2811 | if (__collate_name.empty()) |
| 2812 | throw regex_error(regex_constants::error_brack); |
| 2813 | string_type __equiv_name = |
| 2814 | __traits_.transform_primary(__collate_name.begin(), |
| 2815 | __collate_name.end()); |
| 2816 | if (!__equiv_name.empty()) |
| 2817 | __push_char(__equiv_name); |
| 2818 | else |
| 2819 | __push_char(__collate_name); |
| 2820 | __first = next(__temp, 2); |
| 2821 | return __first; |
| 2822 | } |
| 2823 | |
| 2824 | template <class _CharT, class _Traits> |
| 2825 | template <class _ForwardIterator> |
| 2826 | _ForwardIterator |
| 2827 | basic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first, |
| 2828 | _ForwardIterator __last) |
| 2829 | { |
| 2830 | // Found [: |
| 2831 | // This means :] must exist |
| 2832 | value_type _Colon_close[2] = {':', ']'}; |
| 2833 | _ForwardIterator __temp = _STD::search(__first, __last, _Colon_close, |
| 2834 | _Colon_close+2); |
| 2835 | if (__temp == __last) |
| 2836 | throw regex_error(regex_constants::error_brack); |
| 2837 | // [__first, __temp) contains all text in [: ... :] |
| 2838 | typedef typename _Traits::char_class_type char_class_type; |
| 2839 | char_class_type __class_type = |
| 2840 | __traits_.lookup_classname(__first, __temp, __flags_ & icase); |
| 2841 | if (__class_type == 0) |
| 2842 | throw regex_error(regex_constants::error_brack); |
| 2843 | __push_class_type(__class_type); |
| 2844 | __first = next(__temp, 2); |
| 2845 | return __first; |
| 2846 | } |
| 2847 | |
| 2848 | template <class _CharT, class _Traits> |
| 2849 | template <class _ForwardIterator> |
| 2850 | _ForwardIterator |
| 2851 | basic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first, |
| 2852 | _ForwardIterator __last) |
| 2853 | { |
| 2854 | // Found [. |
| 2855 | // This means .] must exist |
| 2856 | value_type _Dot_close[2] = {'.', ']'}; |
| 2857 | _ForwardIterator __temp = _STD::search(__first, __last, _Dot_close, |
| 2858 | _Dot_close+2); |
| 2859 | if (__temp == __last) |
| 2860 | throw regex_error(regex_constants::error_brack); |
| 2861 | // [__first, __temp) contains all text in [. ... .] |
| 2862 | typedef typename _Traits::string_type string_type; |
| 2863 | string_type __collate_name = |
| 2864 | __traits_.lookup_collatename(__first, __temp); |
| 2865 | if (__collate_name.empty()) |
| 2866 | throw regex_error(regex_constants::error_brack); |
| 2867 | __push_char(__collate_name); |
| 2868 | __first = next(__temp, 2); |
| 2869 | return __first; |
| 2870 | } |
| 2871 | |
| 2872 | template <class _CharT, class _Traits> |
| 2873 | template <class _ForwardIterator> |
| 2874 | _ForwardIterator |
| 2875 | basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first, |
| 2876 | _ForwardIterator __last, |
| 2877 | int& __c) |
| 2878 | { |
| 2879 | if (__first != __last && '0' <= *__first && *__first <= '9') |
| 2880 | { |
| 2881 | __c = *__first - '0'; |
| 2882 | for (++__first; __first != __last && '0' <= *__first && *__first <= '9'; |
| 2883 | ++__first) |
| 2884 | { |
| 2885 | __c *= 10; |
| 2886 | __c += *__first - '0'; |
| 2887 | } |
| 2888 | } |
| 2889 | return __first; |
| 2890 | } |
| 2891 | |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2892 | template <class _CharT, class _Traits> |
| 2893 | void |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2894 | basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max, |
| 2895 | __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end, |
| 2896 | bool __greedy) |
| 2897 | { |
| 2898 | unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first())); |
| 2899 | __end_->first() = nullptr; |
| 2900 | unique_ptr<__loop<_CharT> > __e2; |
| 2901 | if (__mexp_begin != __mexp_end) |
| 2902 | { |
| 2903 | unique_ptr<__zero_marked_exprs<_CharT> > |
| 2904 | __e3(new __zero_marked_exprs<_CharT>(__mexp_begin, __mexp_end, |
| 2905 | __s->first())); |
| 2906 | __s->first() = nullptr; |
| 2907 | __e2.reset(new __loop<_CharT>(__loop_count_, __e3.get(), __e1.get(), |
| 2908 | __greedy, __min, __max)); |
| 2909 | __e3.release(); |
| 2910 | __e1.release(); |
| 2911 | } |
| 2912 | else |
| 2913 | { |
| 2914 | __e2.reset(new __loop<_CharT>(__loop_count_, __s->first(), __e1.get(), |
| 2915 | __greedy, __min, __max)); |
| 2916 | __s->first() = nullptr; |
| 2917 | __e1.release(); |
| 2918 | } |
| 2919 | __end_->first() = new __increment_loop_count<_CharT>(__loop_count_, __e2.get()); |
| 2920 | __end_ = __e2->second(); |
| 2921 | __s->first() = new __zero_loop_count<_CharT>(__loop_count_, __e2.get()); |
| 2922 | __e2.release(); |
| 2923 | ++__loop_count_; |
| 2924 | } |
| 2925 | |
| 2926 | template <class _CharT, class _Traits> |
| 2927 | void |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2928 | basic_regex<_CharT, _Traits>::__push_char(value_type __c) |
| 2929 | { |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2930 | __end_->first() = new __match_char<_CharT>(__c, __end_->first()); |
| 2931 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2932 | } |
| 2933 | |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2934 | template <class _CharT, class _Traits> |
| 2935 | void |
| 2936 | basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression() |
| 2937 | { |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2938 | __end_->first() = new __begin_marked_subexpression<_CharT>(++__marked_count_, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2939 | __end_->first()); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2940 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2941 | } |
| 2942 | |
| 2943 | template <class _CharT, class _Traits> |
| 2944 | void |
| 2945 | basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub) |
| 2946 | { |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2947 | __end_->first() = new __end_marked_subexpression<_CharT>(__sub, |
| 2948 | __end_->first()); |
| 2949 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2950 | } |
| 2951 | |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame^] | 2952 | template <class _CharT, class _Traits> |
| 2953 | void |
| 2954 | basic_regex<_CharT, _Traits>::__push_r_anchor() |
| 2955 | { |
| 2956 | __end_->first() = new __r_anchor<_CharT>(__end_->first()); |
| 2957 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 2958 | } |
| 2959 | |
| 2960 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2961 | typedef basic_regex<char> regex; |
| 2962 | typedef basic_regex<wchar_t> wregex; |
| 2963 | |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2964 | // sub_match |
| 2965 | |
| 2966 | template <class _BidirectionalIterator> |
| 2967 | class sub_match |
| 2968 | : public pair<_BidirectionalIterator, _BidirectionalIterator> |
| 2969 | { |
| 2970 | public: |
| 2971 | typedef _BidirectionalIterator iterator; |
| 2972 | typedef typename iterator_traits<iterator>::value_type value_type; |
| 2973 | typedef typename iterator_traits<iterator>::difference_type difference_type; |
| 2974 | typedef basic_string<value_type> string_type; |
| 2975 | |
| 2976 | bool matched; |
| 2977 | |
| 2978 | difference_type length() const |
| 2979 | {return matched ? _STD::distance(this->first, this->second) : 0;} |
| 2980 | string_type str() const |
| 2981 | {return matched ? string_type(this->first, this->second) : string_type();} |
| 2982 | operator string_type() const |
| 2983 | {return str();} |
| 2984 | |
| 2985 | int compare(const sub_match& __s) const |
| 2986 | {return str().compare(__s.str());} |
| 2987 | int compare(const string_type& __s) const |
| 2988 | {return str().compare(__s);} |
| 2989 | int compare(const value_type* __s) const |
| 2990 | {return str().compare(__s);} |
| 2991 | }; |
| 2992 | |
| 2993 | typedef sub_match<const char*> csub_match; |
| 2994 | typedef sub_match<const wchar_t*> wcsub_match; |
| 2995 | typedef sub_match<string::const_iterator> ssub_match; |
| 2996 | typedef sub_match<wstring::const_iterator> wssub_match; |
| 2997 | |
| 2998 | template <class _BiIter> |
| 2999 | inline _LIBCPP_INLINE_VISIBILITY |
| 3000 | bool |
| 3001 | operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 3002 | { |
| 3003 | return __x.compare(__y) == 0; |
| 3004 | } |
| 3005 | |
| 3006 | template <class _BiIter> |
| 3007 | inline _LIBCPP_INLINE_VISIBILITY |
| 3008 | bool |
| 3009 | operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 3010 | { |
| 3011 | return !(__x == __y); |
| 3012 | } |
| 3013 | |
| 3014 | template <class _BiIter> |
| 3015 | inline _LIBCPP_INLINE_VISIBILITY |
| 3016 | bool |
| 3017 | operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 3018 | { |
| 3019 | return __x.compare(__y) < 0; |
| 3020 | } |
| 3021 | |
| 3022 | template <class _BiIter> |
| 3023 | inline _LIBCPP_INLINE_VISIBILITY |
| 3024 | bool |
| 3025 | operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 3026 | { |
| 3027 | return !(__y < __x); |
| 3028 | } |
| 3029 | |
| 3030 | template <class _BiIter> |
| 3031 | inline _LIBCPP_INLINE_VISIBILITY |
| 3032 | bool |
| 3033 | operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 3034 | { |
| 3035 | return !(__x < __y); |
| 3036 | } |
| 3037 | |
| 3038 | template <class _BiIter> |
| 3039 | inline _LIBCPP_INLINE_VISIBILITY |
| 3040 | bool |
| 3041 | operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 3042 | { |
| 3043 | return __y < __x; |
| 3044 | } |
| 3045 | |
| 3046 | template <class _BiIter, class _ST, class _SA> |
| 3047 | inline _LIBCPP_INLINE_VISIBILITY |
| 3048 | bool |
| 3049 | operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 3050 | const sub_match<_BiIter>& __y) |
| 3051 | { |
| 3052 | return __y.compare(__x.c_str()) == 0; |
| 3053 | } |
| 3054 | |
| 3055 | template <class _BiIter, class _ST, class _SA> |
| 3056 | inline _LIBCPP_INLINE_VISIBILITY |
| 3057 | bool |
| 3058 | operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 3059 | const sub_match<_BiIter>& __y) |
| 3060 | { |
| 3061 | return !(__x == __y); |
| 3062 | } |
| 3063 | |
| 3064 | template <class _BiIter, class _ST, class _SA> |
| 3065 | inline _LIBCPP_INLINE_VISIBILITY |
| 3066 | bool |
| 3067 | operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 3068 | const sub_match<_BiIter>& __y) |
| 3069 | { |
| 3070 | return __y.compare(__x.c_str()) > 0; |
| 3071 | } |
| 3072 | |
| 3073 | template <class _BiIter, class _ST, class _SA> |
| 3074 | inline _LIBCPP_INLINE_VISIBILITY |
| 3075 | bool |
| 3076 | operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 3077 | const sub_match<_BiIter>& __y) |
| 3078 | { |
| 3079 | return __y < __x; |
| 3080 | } |
| 3081 | |
| 3082 | template <class _BiIter, class _ST, class _SA> |
| 3083 | inline _LIBCPP_INLINE_VISIBILITY |
| 3084 | bool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 3085 | const sub_match<_BiIter>& __y) |
| 3086 | { |
| 3087 | return !(__x < __y); |
| 3088 | } |
| 3089 | |
| 3090 | template <class _BiIter, class _ST, class _SA> |
| 3091 | inline _LIBCPP_INLINE_VISIBILITY |
| 3092 | bool |
| 3093 | operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 3094 | const sub_match<_BiIter>& __y) |
| 3095 | { |
| 3096 | return !(__y < __x); |
| 3097 | } |
| 3098 | |
| 3099 | template <class _BiIter, class _ST, class _SA> |
| 3100 | inline _LIBCPP_INLINE_VISIBILITY |
| 3101 | bool |
| 3102 | operator==(const sub_match<_BiIter>& __x, |
| 3103 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 3104 | { |
| 3105 | return __x.compare(__y.c_str()) == 0; |
| 3106 | } |
| 3107 | |
| 3108 | template <class _BiIter, class _ST, class _SA> |
| 3109 | inline _LIBCPP_INLINE_VISIBILITY |
| 3110 | bool |
| 3111 | operator!=(const sub_match<_BiIter>& __x, |
| 3112 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 3113 | { |
| 3114 | return !(__x == __y); |
| 3115 | } |
| 3116 | |
| 3117 | template <class _BiIter, class _ST, class _SA> |
| 3118 | inline _LIBCPP_INLINE_VISIBILITY |
| 3119 | bool |
| 3120 | operator<(const sub_match<_BiIter>& __x, |
| 3121 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 3122 | { |
| 3123 | return __x.compare(__y.c_str()) < 0; |
| 3124 | } |
| 3125 | |
| 3126 | template <class _BiIter, class _ST, class _SA> |
| 3127 | inline _LIBCPP_INLINE_VISIBILITY |
| 3128 | bool operator>(const sub_match<_BiIter>& __x, |
| 3129 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 3130 | { |
| 3131 | return __y < __x; |
| 3132 | } |
| 3133 | |
| 3134 | template <class _BiIter, class _ST, class _SA> |
| 3135 | inline _LIBCPP_INLINE_VISIBILITY |
| 3136 | bool |
| 3137 | operator>=(const sub_match<_BiIter>& __x, |
| 3138 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 3139 | { |
| 3140 | return !(__x < __y); |
| 3141 | } |
| 3142 | |
| 3143 | template <class _BiIter, class _ST, class _SA> |
| 3144 | inline _LIBCPP_INLINE_VISIBILITY |
| 3145 | bool |
| 3146 | operator<=(const sub_match<_BiIter>& __x, |
| 3147 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 3148 | { |
| 3149 | return !(__y < __x); |
| 3150 | } |
| 3151 | |
| 3152 | template <class _BiIter> |
| 3153 | inline _LIBCPP_INLINE_VISIBILITY |
| 3154 | bool |
| 3155 | operator==(typename iterator_traits<_BiIter>::value_type const* __x, |
| 3156 | const sub_match<_BiIter>& __y) |
| 3157 | { |
| 3158 | return __y.compare(__x) == 0; |
| 3159 | } |
| 3160 | |
| 3161 | template <class _BiIter> |
| 3162 | inline _LIBCPP_INLINE_VISIBILITY |
| 3163 | bool |
| 3164 | operator!=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 3165 | const sub_match<_BiIter>& __y) |
| 3166 | { |
| 3167 | return !(__x == __y); |
| 3168 | } |
| 3169 | |
| 3170 | template <class _BiIter> |
| 3171 | inline _LIBCPP_INLINE_VISIBILITY |
| 3172 | bool |
| 3173 | operator<(typename iterator_traits<_BiIter>::value_type const* __x, |
| 3174 | const sub_match<_BiIter>& __y) |
| 3175 | { |
| 3176 | return __y.compare(__x) > 0; |
| 3177 | } |
| 3178 | |
| 3179 | template <class _BiIter> |
| 3180 | inline _LIBCPP_INLINE_VISIBILITY |
| 3181 | bool |
| 3182 | operator>(typename iterator_traits<_BiIter>::value_type const* __x, |
| 3183 | const sub_match<_BiIter>& __y) |
| 3184 | { |
| 3185 | return __y < __x; |
| 3186 | } |
| 3187 | |
| 3188 | template <class _BiIter> |
| 3189 | inline _LIBCPP_INLINE_VISIBILITY |
| 3190 | bool |
| 3191 | operator>=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 3192 | const sub_match<_BiIter>& __y) |
| 3193 | { |
| 3194 | return !(__x < __y); |
| 3195 | } |
| 3196 | |
| 3197 | template <class _BiIter> |
| 3198 | inline _LIBCPP_INLINE_VISIBILITY |
| 3199 | bool |
| 3200 | operator<=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 3201 | const sub_match<_BiIter>& __y) |
| 3202 | { |
| 3203 | return !(__y < __x); |
| 3204 | } |
| 3205 | |
| 3206 | template <class _BiIter> |
| 3207 | inline _LIBCPP_INLINE_VISIBILITY |
| 3208 | bool |
| 3209 | operator==(const sub_match<_BiIter>& __x, |
| 3210 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 3211 | { |
| 3212 | return __x.compare(__y) == 0; |
| 3213 | } |
| 3214 | |
| 3215 | template <class _BiIter> |
| 3216 | inline _LIBCPP_INLINE_VISIBILITY |
| 3217 | bool |
| 3218 | operator!=(const sub_match<_BiIter>& __x, |
| 3219 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 3220 | { |
| 3221 | return !(__x == __y); |
| 3222 | } |
| 3223 | |
| 3224 | template <class _BiIter> |
| 3225 | inline _LIBCPP_INLINE_VISIBILITY |
| 3226 | bool |
| 3227 | operator<(const sub_match<_BiIter>& __x, |
| 3228 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 3229 | { |
| 3230 | return __x.compare(__y) < 0; |
| 3231 | } |
| 3232 | |
| 3233 | template <class _BiIter> |
| 3234 | inline _LIBCPP_INLINE_VISIBILITY |
| 3235 | bool |
| 3236 | operator>(const sub_match<_BiIter>& __x, |
| 3237 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 3238 | { |
| 3239 | return __y < __x; |
| 3240 | } |
| 3241 | |
| 3242 | template <class _BiIter> |
| 3243 | inline _LIBCPP_INLINE_VISIBILITY |
| 3244 | bool |
| 3245 | operator>=(const sub_match<_BiIter>& __x, |
| 3246 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 3247 | { |
| 3248 | return !(__x < __y); |
| 3249 | } |
| 3250 | |
| 3251 | template <class _BiIter> |
| 3252 | inline _LIBCPP_INLINE_VISIBILITY |
| 3253 | bool |
| 3254 | operator<=(const sub_match<_BiIter>& __x, |
| 3255 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 3256 | { |
| 3257 | return !(__y < __x); |
| 3258 | } |
| 3259 | |
| 3260 | template <class _BiIter> |
| 3261 | inline _LIBCPP_INLINE_VISIBILITY |
| 3262 | bool |
| 3263 | operator==(typename iterator_traits<_BiIter>::value_type const& __x, |
| 3264 | const sub_match<_BiIter>& __y) |
| 3265 | { |
| 3266 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 3267 | return __y.compare(string_type(1, __x)) == 0; |
| 3268 | } |
| 3269 | |
| 3270 | template <class _BiIter> |
| 3271 | inline _LIBCPP_INLINE_VISIBILITY |
| 3272 | bool |
| 3273 | operator!=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 3274 | const sub_match<_BiIter>& __y) |
| 3275 | { |
| 3276 | return !(__x == __y); |
| 3277 | } |
| 3278 | |
| 3279 | template <class _BiIter> |
| 3280 | inline _LIBCPP_INLINE_VISIBILITY |
| 3281 | bool |
| 3282 | operator<(typename iterator_traits<_BiIter>::value_type const& __x, |
| 3283 | const sub_match<_BiIter>& __y) |
| 3284 | { |
| 3285 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 3286 | return __y.compare(string_type(1, __x)) > 0; |
| 3287 | } |
| 3288 | |
| 3289 | template <class _BiIter> |
| 3290 | inline _LIBCPP_INLINE_VISIBILITY |
| 3291 | bool |
| 3292 | operator>(typename iterator_traits<_BiIter>::value_type const& __x, |
| 3293 | const sub_match<_BiIter>& __y) |
| 3294 | { |
| 3295 | return __y < __x; |
| 3296 | } |
| 3297 | |
| 3298 | template <class _BiIter> |
| 3299 | inline _LIBCPP_INLINE_VISIBILITY |
| 3300 | bool |
| 3301 | operator>=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 3302 | const sub_match<_BiIter>& __y) |
| 3303 | { |
| 3304 | return !(__x < __y); |
| 3305 | } |
| 3306 | |
| 3307 | template <class _BiIter> |
| 3308 | inline _LIBCPP_INLINE_VISIBILITY |
| 3309 | bool |
| 3310 | operator<=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 3311 | const sub_match<_BiIter>& __y) |
| 3312 | { |
| 3313 | return !(__y < __x); |
| 3314 | } |
| 3315 | |
| 3316 | template <class _BiIter> |
| 3317 | inline _LIBCPP_INLINE_VISIBILITY |
| 3318 | bool |
| 3319 | operator==(const sub_match<_BiIter>& __x, |
| 3320 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 3321 | { |
| 3322 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 3323 | return __x.compare(string_type(1, __y)) == 0; |
| 3324 | } |
| 3325 | |
| 3326 | template <class _BiIter> |
| 3327 | inline _LIBCPP_INLINE_VISIBILITY |
| 3328 | bool |
| 3329 | operator!=(const sub_match<_BiIter>& __x, |
| 3330 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 3331 | { |
| 3332 | return !(__x == __y); |
| 3333 | } |
| 3334 | |
| 3335 | template <class _BiIter> |
| 3336 | inline _LIBCPP_INLINE_VISIBILITY |
| 3337 | bool |
| 3338 | operator<(const sub_match<_BiIter>& __x, |
| 3339 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 3340 | { |
| 3341 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 3342 | return __x.compare(string_type(1, __y)) < 0; |
| 3343 | } |
| 3344 | |
| 3345 | template <class _BiIter> |
| 3346 | inline _LIBCPP_INLINE_VISIBILITY |
| 3347 | bool |
| 3348 | operator>(const sub_match<_BiIter>& __x, |
| 3349 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 3350 | { |
| 3351 | return __y < __x; |
| 3352 | } |
| 3353 | |
| 3354 | template <class _BiIter> |
| 3355 | inline _LIBCPP_INLINE_VISIBILITY |
| 3356 | bool |
| 3357 | operator>=(const sub_match<_BiIter>& __x, |
| 3358 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 3359 | { |
| 3360 | return !(__x < __y); |
| 3361 | } |
| 3362 | |
| 3363 | template <class _BiIter> |
| 3364 | inline _LIBCPP_INLINE_VISIBILITY |
| 3365 | bool |
| 3366 | operator<=(const sub_match<_BiIter>& __x, |
| 3367 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 3368 | { |
| 3369 | return !(__y < __x); |
| 3370 | } |
| 3371 | |
| 3372 | template <class _CharT, class _ST, class _BiIter> |
| 3373 | inline _LIBCPP_INLINE_VISIBILITY |
| 3374 | basic_ostream<_CharT, _ST>& |
| 3375 | operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m) |
| 3376 | { |
| 3377 | return __os << __m.str(); |
| 3378 | } |
| 3379 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 3380 | template <class _BidirectionalIterator, |
| 3381 | class _Allocator = allocator<sub_match<_BidirectionalIterator> > > |
| 3382 | class match_results |
| 3383 | { |
| 3384 | public: |
| 3385 | typedef _Allocator allocator_type; |
| 3386 | typedef sub_match<_BidirectionalIterator> value_type; |
| 3387 | private: |
| 3388 | typedef vector<value_type, allocator_type> __container_type; |
| 3389 | |
| 3390 | __container_type __matches_; |
| 3391 | value_type __unmatched_; |
| 3392 | value_type __prefix_; |
| 3393 | value_type __suffix_; |
| 3394 | public: |
| 3395 | typedef const value_type& const_reference; |
| 3396 | typedef const_reference reference; |
| 3397 | typedef typename __container_type::const_iterator const_iterator; |
| 3398 | typedef const_iterator iterator; |
| 3399 | typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; |
| 3400 | typedef typename allocator_traits<allocator_type>::size_type size_type; |
| 3401 | typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type; |
| 3402 | typedef basic_string<char_type> string_type; |
| 3403 | |
| 3404 | // construct/copy/destroy: |
| 3405 | explicit match_results(const allocator_type& __a = allocator_type()); |
| 3406 | // match_results(const match_results&) = default; |
| 3407 | // match_results& operator=(const match_results&) = default; |
| 3408 | #ifdef _LIBCPP_MOVE |
| 3409 | // match_results(match_results&& __m) = default; |
| 3410 | // match_results& operator=(match_results&& __m) = default; |
| 3411 | #endif |
| 3412 | // ~match_results() = default; |
| 3413 | |
| 3414 | // size: |
| 3415 | size_type size() const {return __matches_.size();} |
| 3416 | size_type max_size() const {return __matches_.max_size();} |
| 3417 | bool empty() const {return size() == 0;} |
| 3418 | |
| 3419 | // element access: |
| 3420 | difference_type length(size_type __sub = 0) const |
| 3421 | {return (*this)[__sub].length();} |
| 3422 | difference_type position(size_type __sub = 0) const |
| 3423 | {return _STD::distance(__prefix_.first, (*this)[__sub].first);} |
| 3424 | string_type str(size_type __sub = 0) const |
| 3425 | {return (*this)[__sub].str();} |
| 3426 | const_reference operator[](size_type __n) const |
| 3427 | {return __n < __matches_.size() ? __matches_[__n] : __unmatched_;} |
| 3428 | |
| 3429 | const_reference prefix() const {return __prefix_;} |
| 3430 | const_reference suffix() const {return __suffix_;} |
| 3431 | |
| 3432 | const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin() + 1;} |
| 3433 | const_iterator end() const {return __matches_.end();} |
| 3434 | const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin() + 1;} |
| 3435 | const_iterator cend() const {return __matches_.end();} |
| 3436 | |
| 3437 | // format: |
| 3438 | template <class _OutputIter> |
| 3439 | _OutputIter |
| 3440 | format(_OutputIter __out, const char_type* __fmt_first, |
| 3441 | const char_type* __fmt_last, |
| 3442 | regex_constants::match_flag_type __flags = regex_constants::format_default) const; |
| 3443 | template <class _OutputIter, class _ST, class _SA> |
| 3444 | _OutputIter |
| 3445 | format(_OutputIter __out, const basic_string<char_type, _ST, _SA>& __fmt, |
| 3446 | regex_constants::match_flag_type __flags = regex_constants::format_default) const; |
| 3447 | template <class _ST, class _SA> |
| 3448 | basic_string<char_type, _ST, _SA> |
| 3449 | format(const basic_string<char_type, _ST, _SA>& __fmt, |
| 3450 | regex_constants::match_flag_type __flags = regex_constants::format_default) const; |
| 3451 | string_type |
| 3452 | format(const char_type* __fmt, |
| 3453 | regex_constants::match_flag_type __flags = regex_constants::format_default) const; |
| 3454 | |
| 3455 | // allocator: |
| 3456 | allocator_type get_allocator() const {return __matches_.get_allocator();} |
| 3457 | |
| 3458 | // swap: |
| 3459 | void swap(match_results& __m); |
| 3460 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3461 | private: |
| 3462 | void __init(unsigned __s, |
| 3463 | _BidirectionalIterator __f, _BidirectionalIterator __l); |
| 3464 | |
| 3465 | template <class, class> friend class basic_regex; |
| 3466 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 3467 | template <class _B, class _A, class _C, class _T> |
| 3468 | friend |
| 3469 | bool |
| 3470 | regex_match(_B, _B, match_results<_B, _A>&, const basic_regex<_C, _T>&, |
| 3471 | regex_constants::match_flag_type); |
| 3472 | }; |
| 3473 | |
| 3474 | template <class _BidirectionalIterator, class _Allocator> |
| 3475 | match_results<_BidirectionalIterator, _Allocator>::match_results( |
| 3476 | const allocator_type& __a) |
| 3477 | : __matches_(__a), |
| 3478 | __unmatched_(), |
| 3479 | __prefix_(), |
| 3480 | __suffix_() |
| 3481 | { |
| 3482 | } |
| 3483 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3484 | template <class _BidirectionalIterator, class _Allocator> |
| 3485 | void |
| 3486 | match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s, |
| 3487 | _BidirectionalIterator __f, _BidirectionalIterator __l) |
| 3488 | { |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3489 | __unmatched_.first = __l; |
| 3490 | __unmatched_.second = __l; |
| 3491 | __unmatched_.matched = false; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3492 | __matches_.assign(__s, __unmatched_); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3493 | __prefix_.first = __f; |
| 3494 | __prefix_.second = __f; |
| 3495 | __prefix_.matched = false; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3496 | __suffix_ = __unmatched_; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3497 | } |
| 3498 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 3499 | typedef match_results<const char*> cmatch; |
| 3500 | typedef match_results<const wchar_t*> wcmatch; |
| 3501 | typedef match_results<string::const_iterator> smatch; |
| 3502 | typedef match_results<wstring::const_iterator> wsmatch; |
| 3503 | |
| 3504 | template <class _BidirectionalIterator, class _Allocator> |
| 3505 | bool |
| 3506 | operator==(const match_results<_BidirectionalIterator, _Allocator>& __x, |
| 3507 | const match_results<_BidirectionalIterator, _Allocator>& __y); |
| 3508 | |
| 3509 | template <class _BidirectionalIterator, class _Allocator> |
| 3510 | bool |
| 3511 | operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x, |
| 3512 | const match_results<_BidirectionalIterator, _Allocator>& __y); |
| 3513 | |
| 3514 | template <class _BidirectionalIterator, class _Allocator> |
| 3515 | void |
| 3516 | swap(match_results<_BidirectionalIterator, _Allocator>& __x, |
| 3517 | match_results<_BidirectionalIterator, _Allocator>& __y); |
| 3518 | |
| 3519 | // regex_search |
| 3520 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3521 | template <class _CharT, class _Traits> |
| 3522 | template <class _BidirectionalIterator, class _Allocator> |
| 3523 | bool |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3524 | basic_regex<_CharT, _Traits>::__match_at_start_ecma( |
| 3525 | _BidirectionalIterator __first, _BidirectionalIterator __last, |
| 3526 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 3527 | regex_constants::match_flag_type __flags) const |
| 3528 | { |
| 3529 | return false; |
| 3530 | } |
| 3531 | |
| 3532 | template <class _CharT, class _Traits> |
| 3533 | template <class _BidirectionalIterator, class _Allocator> |
| 3534 | bool |
| 3535 | basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs( |
| 3536 | const _CharT* __first, const _CharT* __last, |
| 3537 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 3538 | vector<size_t>& __lc, |
| 3539 | regex_constants::match_flag_type __flags) const |
| 3540 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3541 | typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; |
| 3542 | __split_buffer<__command> __commands; |
| 3543 | difference_type __j = 0; |
| 3544 | difference_type __highest_j = 0; |
| 3545 | difference_type _N = _STD::distance(__first, __last); |
| 3546 | __state* __st = __start_.get(); |
| 3547 | if (__st) |
| 3548 | { |
| 3549 | __commands.push_front(__command(__st)); |
| 3550 | __commands.push_front(__command(__command::__consume_input)); |
| 3551 | _BidirectionalIterator __current = __first; |
| 3552 | do |
| 3553 | { |
| 3554 | __command __cmd = __commands.back(); |
| 3555 | __commands.pop_back(); |
| 3556 | if (__cmd.first != nullptr) |
| 3557 | __cmd = __cmd.first->__test(__first, __current, __last, __lc, |
| 3558 | __m.__matches_.data(), __flags); |
| 3559 | switch (__cmd.__do_) |
| 3560 | { |
| 3561 | case __command::__end_state: |
| 3562 | __highest_j = _STD::max(__highest_j, __j); |
| 3563 | break; |
| 3564 | case __command::__consume_input: |
| 3565 | if (__j == _N) |
| 3566 | return false; |
| 3567 | ++__current; |
| 3568 | if (++__j != _N && !__commands.empty()) |
| 3569 | __commands.push_front(__command(__command::__consume_input)); |
| 3570 | break; |
| 3571 | case __command::__accept_and_consume: |
| 3572 | __commands.push_front(__command(__cmd.first)); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3573 | break; |
| 3574 | case __command::__accept_but_not_consume: |
| 3575 | __commands.push_back(__command(__cmd.first)); |
| 3576 | if (__cmd.second != nullptr) |
| 3577 | __commands.push_back(__command(__cmd.second)); |
| 3578 | break; |
| 3579 | case __command::__reject: |
| 3580 | break; |
| 3581 | default: |
| 3582 | throw regex_error(regex_constants::error_temp); |
| 3583 | break; |
| 3584 | } |
| 3585 | } while (!__commands.empty()); |
| 3586 | if (__highest_j != 0) |
| 3587 | { |
| 3588 | __m.__matches_[0].first = __first; |
| 3589 | __m.__matches_[0].second = _STD::next(__first, __highest_j); |
| 3590 | __m.__matches_[0].matched = true; |
| 3591 | return true; |
| 3592 | } |
| 3593 | } |
| 3594 | return false; |
| 3595 | } |
| 3596 | |
| 3597 | template <class _CharT, class _Traits> |
| 3598 | template <class _BidirectionalIterator, class _Allocator> |
| 3599 | bool |
| 3600 | basic_regex<_CharT, _Traits>::__match_at_start_posix_subs( |
| 3601 | _BidirectionalIterator __first, _BidirectionalIterator __last, |
| 3602 | match_results<_BidirectionalIterator, _Allocator>& __m, |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3603 | vector<size_t>& __lc, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3604 | regex_constants::match_flag_type __flags) const |
| 3605 | { |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3606 | typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; |
| 3607 | vector<__command> __commands; |
| 3608 | vector<_BidirectionalIterator> __current_stack; |
| 3609 | vector<sub_match<_BidirectionalIterator> > __saved_matches; |
| 3610 | vector<sub_match<_BidirectionalIterator> > __best_matches; |
| 3611 | difference_type __j = 0; |
| 3612 | difference_type __highest_j = 0; |
| 3613 | difference_type _N = _STD::distance(__first, __last); |
| 3614 | __state* __st = __start_.get(); |
| 3615 | if (__st) |
| 3616 | { |
| 3617 | __commands.push_back(__command(__st)); |
| 3618 | _BidirectionalIterator __current = __first; |
| 3619 | do |
| 3620 | { |
| 3621 | __command __cmd = __commands.back(); |
| 3622 | __commands.pop_back(); |
| 3623 | if (__cmd.first != nullptr) |
| 3624 | __cmd = __cmd.first->__test(__first, __current, __last, __lc, |
| 3625 | __m.__matches_.data(), __flags); |
| 3626 | switch (__cmd.__do_) |
| 3627 | { |
| 3628 | case __command::__end_state: |
| 3629 | if (__highest_j < __j) |
| 3630 | { |
| 3631 | __highest_j = __j; |
| 3632 | for (unsigned __i = 1; __i < __m.__matches_.size(); ++__i) |
| 3633 | __best_matches.push_back(__m.__matches_[__i]); |
| 3634 | } |
| 3635 | break; |
| 3636 | case __command::__pop_state: |
| 3637 | for (unsigned __i = __m.__matches_.size(); __i > 1;) |
| 3638 | { |
| 3639 | assert(!__saved_matches.empty()); |
| 3640 | __m.__matches_[--__i] = __saved_matches.back(); |
| 3641 | __saved_matches.pop_back(); |
| 3642 | } |
| 3643 | assert(!__current_stack.empty()); |
| 3644 | __current = __current_stack.back(); |
| 3645 | __current_stack.pop_back(); |
| 3646 | break; |
| 3647 | case __command::__accept_and_consume: |
| 3648 | __commands.push_back(__command(__cmd.first)); |
| 3649 | if (__current != __last) |
| 3650 | { |
| 3651 | ++__current; |
| 3652 | ++__j; |
| 3653 | } |
| 3654 | break; |
| 3655 | case __command::__accept_but_not_consume: |
| 3656 | if (__cmd.second != nullptr) |
| 3657 | { |
| 3658 | __commands.push_back(__command(__cmd.second)); |
| 3659 | __commands.push_back(__command(__command::__pop_state)); |
| 3660 | __current_stack.push_back(__current); |
| 3661 | for (unsigned __i = 1; __i < __m.__matches_.size(); ++__i) |
| 3662 | __saved_matches.push_back(__m.__matches_[__i]); |
| 3663 | } |
| 3664 | __commands.push_back(__command(__cmd.first)); |
| 3665 | break; |
| 3666 | case __command::__reject: |
| 3667 | break; |
| 3668 | default: |
| 3669 | throw regex_error(regex_constants::error_temp); |
| 3670 | break; |
| 3671 | } |
| 3672 | } while (!__commands.empty()); |
| 3673 | if (__highest_j != 0) |
| 3674 | { |
| 3675 | __m.__matches_[0].first = __first; |
| 3676 | __m.__matches_[0].second = _STD::next(__first, __highest_j); |
| 3677 | __m.__matches_[0].matched = true; |
| 3678 | for (unsigned __i = __m.__matches_.size(); __i > 1;) |
| 3679 | { |
| 3680 | assert(!__best_matches.empty()); |
| 3681 | __m.__matches_[--__i] = __best_matches.back(); |
| 3682 | __best_matches.pop_back(); |
| 3683 | } |
| 3684 | return true; |
| 3685 | } |
| 3686 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3687 | return false; |
| 3688 | } |
| 3689 | |
| 3690 | template <class _CharT, class _Traits> |
| 3691 | template <class _BidirectionalIterator, class _Allocator> |
| 3692 | bool |
| 3693 | basic_regex<_CharT, _Traits>::__match_at_start( |
| 3694 | _BidirectionalIterator __first, _BidirectionalIterator __last, |
| 3695 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 3696 | vector<size_t>& __lc, |
| 3697 | regex_constants::match_flag_type __flags) const |
| 3698 | { |
| 3699 | if (__flags_ & ECMAScript) |
| 3700 | return __match_at_start_ecma(__first, __last, __m, __flags); |
| 3701 | if (mark_count() == 0) |
| 3702 | return __match_at_start_posix_nosubs(__first, __last, __m, __lc, __flags); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3703 | return __match_at_start_posix_subs(__first, __last, __m, __lc, __flags); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3704 | } |
| 3705 | |
| 3706 | template <class _CharT, class _Traits> |
| 3707 | template <class _BidirectionalIterator, class _Allocator> |
| 3708 | bool |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3709 | basic_regex<_CharT, _Traits>::__search( |
| 3710 | _BidirectionalIterator __first, _BidirectionalIterator __last, |
| 3711 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 3712 | regex_constants::match_flag_type __flags) const |
| 3713 | { |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame^] | 3714 | if (__left_anchor_) |
| 3715 | __flags |= regex_constants::match_continuous; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3716 | __m.__init(1 + mark_count(), __first, __last); |
| 3717 | vector<size_t> __lc(__loop_count()); |
| 3718 | if (__match_at_start(__first, __last, __m, __lc, __flags)) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3719 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3720 | __m.__prefix_.second = __m[0].first; |
| 3721 | __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; |
| 3722 | __m.__suffix_.first = __m[0].second; |
| 3723 | __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; |
| 3724 | return true; |
| 3725 | } |
| 3726 | if (!(__flags & regex_constants::match_continuous)) |
| 3727 | { |
| 3728 | __m.__matches_.assign(__m.size(), __m.__unmatched_); |
| 3729 | for (++__first; __first != __last; ++__first) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3730 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3731 | if (__match_at_start(__first, __last, __m, __lc, __flags)) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3732 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3733 | __m.__prefix_.second = __m[0].first; |
| 3734 | __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; |
| 3735 | __m.__suffix_.first = __m[0].second; |
| 3736 | __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; |
| 3737 | return true; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3738 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3739 | __m.__matches_.assign(__m.size(), __m.__unmatched_); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3740 | } |
| 3741 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3742 | __m.__matches_.clear(); |
| 3743 | return false; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3744 | } |
| 3745 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 3746 | template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3747 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 3748 | bool |
| 3749 | regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 3750 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 3751 | const basic_regex<_CharT, _Traits>& __e, |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3752 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 3753 | { |
| 3754 | return __e.__search(__first, __last, __m, __flags); |
| 3755 | } |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 3756 | |
| 3757 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 3758 | inline _LIBCPP_INLINE_VISIBILITY |
| 3759 | bool |
| 3760 | regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 3761 | const basic_regex<_CharT, _Traits>& __e, |
| 3762 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 3763 | { |
| 3764 | match_results<_BidirectionalIterator> __m; |
| 3765 | return _STD::regex_search(__first, __last, __m, __e, __flags); |
| 3766 | } |
| 3767 | |
| 3768 | template <class _CharT, class _Allocator, class _Traits> |
| 3769 | inline _LIBCPP_INLINE_VISIBILITY |
| 3770 | bool |
| 3771 | regex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, |
| 3772 | const basic_regex<_CharT, _Traits>& __e, |
| 3773 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 3774 | { |
| 3775 | return _STD::regex_search(__str, __str + _Traits::length(__str), __m, __e, __flags); |
| 3776 | } |
| 3777 | |
| 3778 | template <class _CharT, class _Traits> |
| 3779 | inline _LIBCPP_INLINE_VISIBILITY |
| 3780 | bool |
| 3781 | regex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, |
| 3782 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 3783 | { |
| 3784 | return _STD::regex_search(__str, __str + _Traits::length(__str), __e, __flags); |
| 3785 | } |
| 3786 | |
| 3787 | template <class _ST, class _SA, class _CharT, class _Traits> |
| 3788 | inline _LIBCPP_INLINE_VISIBILITY |
| 3789 | bool |
| 3790 | regex_search(const basic_string<_CharT, _ST, _SA>& __s, |
| 3791 | const basic_regex<_CharT, _Traits>& __e, |
| 3792 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 3793 | { |
| 3794 | return _STD::regex_search(__s.begin(), __s.end(), __e, __flags); |
| 3795 | } |
| 3796 | |
| 3797 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 3798 | inline _LIBCPP_INLINE_VISIBILITY |
| 3799 | bool |
| 3800 | regex_search(const basic_string<_CharT, _ST, _SA>& __s, |
| 3801 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 3802 | const basic_regex<_CharT, _Traits>& __e, |
| 3803 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 3804 | { |
| 3805 | return _STD::regex_search(__s.begin(), __s.end(), __m, __e, __flags); |
| 3806 | } |
| 3807 | |
| 3808 | // regex_match |
| 3809 | |
| 3810 | template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> |
| 3811 | bool |
| 3812 | regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 3813 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 3814 | const basic_regex<_CharT, _Traits>& __e, |
| 3815 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 3816 | { |
| 3817 | bool __r = _STD::regex_search(__first, __last, __m, __e, |
| 3818 | __flags | regex_constants::match_continuous); |
| 3819 | if (__r) |
| 3820 | { |
| 3821 | __r = !__m.suffix().matched; |
| 3822 | if (!__r) |
| 3823 | __m.__matches_.clear(); |
| 3824 | } |
| 3825 | return __r; |
| 3826 | } |
| 3827 | |
| 3828 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 3829 | inline _LIBCPP_INLINE_VISIBILITY |
| 3830 | bool |
| 3831 | regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 3832 | const basic_regex<_CharT, _Traits>& __e, |
| 3833 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 3834 | { |
| 3835 | match_results<_BidirectionalIterator> __m; |
| 3836 | return _STD::regex_match(__first, __last, __m, __e, __flags); |
| 3837 | } |
| 3838 | |
| 3839 | template <class _CharT, class _Allocator, class _Traits> |
| 3840 | inline _LIBCPP_INLINE_VISIBILITY |
| 3841 | bool |
| 3842 | regex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, |
| 3843 | const basic_regex<_CharT, _Traits>& __e, |
| 3844 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 3845 | { |
| 3846 | return _STD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags); |
| 3847 | } |
| 3848 | |
| 3849 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 3850 | inline _LIBCPP_INLINE_VISIBILITY |
| 3851 | bool |
| 3852 | regex_match(const basic_string<_CharT, _ST, _SA>& __s, |
| 3853 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 3854 | const basic_regex<_CharT, _Traits>& __e, |
| 3855 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 3856 | { |
| 3857 | return _STD::regex_match(__s.begin(), __s.end(), __m, __e, __flags); |
| 3858 | } |
| 3859 | |
| 3860 | template <class _CharT, class _Traits> |
| 3861 | inline _LIBCPP_INLINE_VISIBILITY |
| 3862 | bool |
| 3863 | regex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, |
| 3864 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 3865 | { |
| 3866 | return _STD::regex_match(__str, __str + _Traits::length(__str), __e, __flags); |
| 3867 | } |
| 3868 | |
| 3869 | template <class _ST, class _SA, class _CharT, class _Traits> |
| 3870 | inline _LIBCPP_INLINE_VISIBILITY |
| 3871 | bool |
| 3872 | regex_match(const basic_string<_CharT, _ST, _SA>& __s, |
| 3873 | const basic_regex<_CharT, _Traits>& __e, |
| 3874 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 3875 | { |
| 3876 | return _STD::regex_match(__s.begin(), __s.end(), __e, __flags); |
| 3877 | } |
| 3878 | |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 3879 | _LIBCPP_END_NAMESPACE_STD |
| 3880 | |
| 3881 | #endif // _LIBCPP_REGEX |