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 | |
| 1241 | typedef __state<_CharT> __state; |
| 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 | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1278 | typedef __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 | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1299 | typedef __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: |
| 1369 | typedef __command<_CharT> __command; |
| 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: |
| 1402 | typedef __command<_CharT> __command; |
| 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: |
| 1466 | typedef __command<_CharT> __command; |
| 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: |
| 1527 | typedef __command<_CharT> __command; |
| 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: |
| 1568 | typedef __command<_CharT> __command; |
| 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: |
| 1610 | typedef __command<_CharT> __command; |
| 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: |
| 1656 | typedef __command<_CharT> __command; |
| 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: |
| 1696 | typedef __command<_CharT> __command; |
| 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 | |
| 1727 | // __state_arg |
| 1728 | |
| 1729 | template <class _CharT> |
| 1730 | class __state_arg |
| 1731 | : public __owns_one_state<_CharT> |
| 1732 | { |
| 1733 | typedef __owns_one_state<_CharT> base; |
| 1734 | |
| 1735 | unsigned __arg_; |
| 1736 | |
| 1737 | __state_arg(const __state_arg&); |
| 1738 | __state_arg& operator=(const __state_arg&); |
| 1739 | public: |
| 1740 | typedef __command<_CharT> __command; |
| 1741 | |
| 1742 | __state_arg(unsigned __a, __state<_CharT>* __s) |
| 1743 | : base(__s), __arg_(__a) {} |
| 1744 | |
| 1745 | virtual __command __test(const _CharT*, const _CharT*, |
| 1746 | const _CharT*, |
| 1747 | vector<size_t>&, |
| 1748 | sub_match<const _CharT*>*, |
| 1749 | regex_constants::match_flag_type) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame^] | 1750 | |
| 1751 | virtual string speak() const |
| 1752 | { |
| 1753 | ostringstream os; |
| 1754 | os << "state arg " << __arg_; |
| 1755 | return os.str(); |
| 1756 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1757 | }; |
| 1758 | |
| 1759 | template <class _CharT> |
| 1760 | __command<_CharT> |
| 1761 | __state_arg<_CharT>::__test(const _CharT*, const _CharT* __c, const _CharT*, |
| 1762 | vector<size_t>&, |
| 1763 | sub_match<const _CharT*>*, |
| 1764 | regex_constants::match_flag_type) const |
| 1765 | { |
| 1766 | return __command(__arg_, this->first()); |
| 1767 | } |
| 1768 | |
| 1769 | // __match_char |
| 1770 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1771 | template <class _CharT> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1772 | class __match_char |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1773 | : public __owns_one_state<_CharT> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1774 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1775 | typedef __owns_one_state<_CharT> base; |
| 1776 | |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1777 | _CharT __c_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1778 | |
| 1779 | __match_char(const __match_char&); |
| 1780 | __match_char& operator=(const __match_char&); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1781 | public: |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1782 | typedef __command<_CharT> __command; |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1783 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1784 | __match_char(_CharT __c, __state<_CharT>* __s) |
| 1785 | : base(__s), __c_(__c) {} |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1786 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1787 | virtual __command __test(const _CharT*, const _CharT* __c, |
| 1788 | const _CharT*, |
| 1789 | vector<size_t>&, |
| 1790 | sub_match<const _CharT*>*, |
| 1791 | regex_constants::match_flag_type) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame^] | 1792 | |
| 1793 | virtual string speak() const |
| 1794 | { |
| 1795 | ostringstream os; |
| 1796 | os << "match char " << __c_; |
| 1797 | return os.str(); |
| 1798 | } |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1799 | }; |
| 1800 | |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1801 | template <class _CharT> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1802 | __command<_CharT> |
| 1803 | __match_char<_CharT>::__test(const _CharT*, const _CharT* __c, |
| 1804 | const _CharT*, |
| 1805 | vector<size_t>&, |
| 1806 | sub_match<const _CharT*>*, |
| 1807 | regex_constants::match_flag_type) const |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1808 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1809 | return __c_ == *__c ? |
| 1810 | __command(__command::__accept_and_consume, this->first()) : __command(); |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1811 | } |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1812 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1813 | template <class, class> class match_results; |
| 1814 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 1815 | template <class _CharT, class _Traits = regex_traits<_CharT> > |
| 1816 | class basic_regex |
| 1817 | { |
| 1818 | public: |
| 1819 | // types: |
| 1820 | typedef _CharT value_type; |
| 1821 | typedef regex_constants::syntax_option_type flag_type; |
| 1822 | typedef typename _Traits::locale_type locale_type; |
| 1823 | |
| 1824 | private: |
| 1825 | _Traits __traits_; |
| 1826 | flag_type __flags_; |
| 1827 | unsigned __marked_count_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1828 | unsigned __loop_count_; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1829 | int __open_count_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1830 | shared_ptr<__empty_state<_CharT> > __start_; |
| 1831 | __owns_one_state<_CharT>* __end_; |
| 1832 | |
| 1833 | typedef __command<_CharT> __command; |
| 1834 | typedef __state<_CharT> __state; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 1835 | |
| 1836 | public: |
| 1837 | // constants: |
| 1838 | static const/*expr*/ regex_constants::syntax_option_type icase = regex_constants::icase; |
| 1839 | static const/*expr*/ regex_constants::syntax_option_type nosubs = regex_constants::nosubs; |
| 1840 | static const/*expr*/ regex_constants::syntax_option_type optimize = regex_constants::optimize; |
| 1841 | static const/*expr*/ regex_constants::syntax_option_type collate = regex_constants::collate; |
| 1842 | static const/*expr*/ regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript; |
| 1843 | static const/*expr*/ regex_constants::syntax_option_type basic = regex_constants::basic; |
| 1844 | static const/*expr*/ regex_constants::syntax_option_type extended = regex_constants::extended; |
| 1845 | static const/*expr*/ regex_constants::syntax_option_type awk = regex_constants::awk; |
| 1846 | static const/*expr*/ regex_constants::syntax_option_type grep = regex_constants::grep; |
| 1847 | static const/*expr*/ regex_constants::syntax_option_type egrep = regex_constants::egrep; |
| 1848 | |
| 1849 | // construct/copy/destroy: |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1850 | basic_regex() |
| 1851 | : __flags_(), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(0) |
| 1852 | {} |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 1853 | explicit basic_regex(const value_type* __p, flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1854 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(0) |
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 | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1857 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(0) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 1858 | {__parse(__p, __p + __len);} |
| 1859 | basic_regex(const basic_regex&); |
| 1860 | #ifdef _LIBCPP_MOVE |
| 1861 | basic_regex(basic_regex&&); |
| 1862 | #endif |
| 1863 | template <class _ST, class _SA> |
| 1864 | explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p, |
| 1865 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1866 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(0) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 1867 | {__parse(__p.begin(), __p.end());} |
| 1868 | template <class _ForwardIterator> |
| 1869 | basic_regex(_ForwardIterator __first, _ForwardIterator __last, |
| 1870 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1871 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(0) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 1872 | {__parse(__first, __last);} |
| 1873 | basic_regex(initializer_list<value_type> __il, |
| 1874 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1875 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(0) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 1876 | {__parse(__il.begin(), __il.end());} |
| 1877 | |
| 1878 | ~basic_regex(); |
| 1879 | |
| 1880 | basic_regex& operator=(const basic_regex&); |
| 1881 | #ifdef _LIBCPP_MOVE |
| 1882 | basic_regex& operator=(basic_regex&&); |
| 1883 | #endif |
| 1884 | basic_regex& operator=(const value_type* __p); |
| 1885 | basic_regex& operator=(initializer_list<value_type> __il); |
| 1886 | template <class _ST, class _SA> |
| 1887 | basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p); |
| 1888 | |
| 1889 | // assign: |
| 1890 | basic_regex& assign(const basic_regex& __that); |
| 1891 | #ifdef _LIBCPP_MOVE |
| 1892 | basic_regex& assign(basic_regex&& __that); |
| 1893 | #endif |
| 1894 | basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript); |
| 1895 | basic_regex& assign(const value_type* __p, size_t __len, flag_type __f); |
| 1896 | template <class _ST, class _SA> |
| 1897 | basic_regex& assign(const basic_string<value_type, _ST, _SA>& __s, |
| 1898 | flag_type __f = regex_constants::ECMAScript); |
| 1899 | template <class _InputIterator> |
| 1900 | basic_regex& assign(_InputIterator __first, _InputIterator __last, |
| 1901 | flag_type __f = regex_constants::ECMAScript); |
| 1902 | basic_regex& assign(initializer_list<value_type> __il, |
| 1903 | flag_type = regex_constants::ECMAScript); |
| 1904 | |
| 1905 | // const operations: |
| 1906 | unsigned mark_count() const {return __marked_count_;} |
| 1907 | flag_type flags() const {return __flags_;} |
| 1908 | |
| 1909 | // locale: |
| 1910 | locale_type imbue(locale_type __loc) {return __traits_.imbue(__loc);} |
| 1911 | locale_type getloc() const {return __traits_.getloc();} |
| 1912 | |
| 1913 | // swap: |
| 1914 | void swap(basic_regex&); |
| 1915 | |
| 1916 | private: |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1917 | unsigned __loop_count() const {return __loop_count_;} |
| 1918 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 1919 | template <class _ForwardIterator> |
| 1920 | void __parse(_ForwardIterator __first, _ForwardIterator __last); |
| 1921 | template <class _ForwardIterator> |
| 1922 | _ForwardIterator |
| 1923 | __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 1924 | template <class _ForwardIterator> |
| 1925 | _ForwardIterator |
| 1926 | __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 1927 | template <class _ForwardIterator> |
| 1928 | _ForwardIterator |
| 1929 | __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 1930 | template <class _ForwardIterator> |
| 1931 | _ForwardIterator |
| 1932 | __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 1933 | template <class _ForwardIterator> |
| 1934 | _ForwardIterator |
| 1935 | __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 1936 | template <class _ForwardIterator> |
| 1937 | _ForwardIterator |
| 1938 | __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last); |
| 1939 | template <class _ForwardIterator> |
| 1940 | _ForwardIterator |
| 1941 | __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last); |
| 1942 | template <class _ForwardIterator> |
| 1943 | _ForwardIterator |
| 1944 | __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last); |
| 1945 | template <class _ForwardIterator> |
| 1946 | _ForwardIterator |
| 1947 | __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last); |
| 1948 | template <class _ForwardIterator> |
| 1949 | _ForwardIterator |
| 1950 | __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last); |
| 1951 | template <class _ForwardIterator> |
| 1952 | _ForwardIterator |
| 1953 | __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last); |
| 1954 | template <class _ForwardIterator> |
| 1955 | _ForwardIterator |
| 1956 | __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last); |
| 1957 | template <class _ForwardIterator> |
| 1958 | _ForwardIterator |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1959 | __parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last, |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame^] | 1960 | __owns_one_state<_CharT>* __s, |
| 1961 | unsigned __mexp_begin, unsigned __mexp_end); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 1962 | template <class _ForwardIterator> |
| 1963 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1964 | __parse_ERE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last); |
| 1965 | template <class _ForwardIterator> |
| 1966 | _ForwardIterator |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 1967 | __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 1968 | template <class _ForwardIterator> |
| 1969 | _ForwardIterator |
| 1970 | __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last); |
| 1971 | template <class _ForwardIterator> |
| 1972 | _ForwardIterator |
| 1973 | __parse_expression_term(_ForwardIterator __first, _ForwardIterator __last); |
| 1974 | template <class _ForwardIterator> |
| 1975 | _ForwardIterator |
| 1976 | __parse_equivalence_class(_ForwardIterator __first, _ForwardIterator __last); |
| 1977 | template <class _ForwardIterator> |
| 1978 | _ForwardIterator |
| 1979 | __parse_character_class(_ForwardIterator __first, _ForwardIterator __last); |
| 1980 | template <class _ForwardIterator> |
| 1981 | _ForwardIterator |
| 1982 | __parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last); |
| 1983 | template <class _ForwardIterator> |
| 1984 | _ForwardIterator |
| 1985 | __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1986 | template <class _ForwardIterator> |
| 1987 | _ForwardIterator |
| 1988 | __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 1989 | template <class _ForwardIterator> |
| 1990 | _ForwardIterator |
| 1991 | __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last); |
| 1992 | template <class _ForwardIterator> |
| 1993 | _ForwardIterator |
| 1994 | __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 1995 | template <class _ForwardIterator> |
| 1996 | _ForwardIterator |
| 1997 | __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last); |
| 1998 | template <class _ForwardIterator> |
| 1999 | _ForwardIterator |
| 2000 | __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last); |
| 2001 | template <class _ForwardIterator> |
| 2002 | _ForwardIterator |
| 2003 | __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2004 | |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2005 | void __push_l_anchor() {} |
| 2006 | void __push_r_anchor() {} |
| 2007 | void __push_match_any() {} |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame^] | 2008 | void __push_greedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s, |
| 2009 | unsigned __mexp_begin = 0, unsigned __mexp_end = 0) |
| 2010 | {__push_loop(__min, numeric_limits<size_t>::max(), __s, |
| 2011 | __mexp_begin, __mexp_end);} |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2012 | void __push_exact_repeat(int __count) {} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2013 | void __push_loop(size_t __min, size_t __max, __owns_one_state<_CharT>* __s, |
| 2014 | size_t __mexp_begin = 0, size_t __mexp_end = 0, |
| 2015 | bool __greedy = true); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2016 | void __start_nonmatching_list() {} |
| 2017 | void __start_matching_list() {} |
| 2018 | void __end_nonmatching_list() {} |
| 2019 | void __end_matching_list() {} |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2020 | void __push_char(value_type __c); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2021 | void __push_char(const typename _Traits::string_type& __c) {} |
| 2022 | void __push_range() {} |
| 2023 | void __push_class_type(typename _Traits::char_class_type) {} |
| 2024 | void __push_back_ref(int __i) {} |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2025 | void __push_alternation() {} |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2026 | void __push_begin_marked_subexpression(); |
| 2027 | void __push_end_marked_subexpression(unsigned); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2028 | |
| 2029 | template <class _BidirectionalIterator, class _Allocator> |
| 2030 | bool |
| 2031 | __search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 2032 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 2033 | regex_constants::match_flag_type __flags) const; |
| 2034 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2035 | template <class _BidirectionalIterator, class _Allocator> |
| 2036 | bool |
| 2037 | __match_at_start(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 2038 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 2039 | vector<size_t>& __lc, |
| 2040 | regex_constants::match_flag_type __flags) const; |
| 2041 | template <class _BidirectionalIterator, class _Allocator> |
| 2042 | bool |
| 2043 | __match_at_start_ecma(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 2044 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 2045 | regex_constants::match_flag_type __flags) const; |
| 2046 | template <class _BidirectionalIterator, class _Allocator> |
| 2047 | bool |
| 2048 | __match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last, |
| 2049 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 2050 | vector<size_t>& __lc, |
| 2051 | regex_constants::match_flag_type __flags) const; |
| 2052 | template <class _BidirectionalIterator, class _Allocator> |
| 2053 | bool |
| 2054 | __match_at_start_posix_subs(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 2055 | match_results<_BidirectionalIterator, _Allocator>& __m, |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame^] | 2056 | vector<size_t>& __lc, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2057 | regex_constants::match_flag_type __flags) const; |
| 2058 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2059 | template <class _B, class _A, class _C, class _T> |
| 2060 | friend |
| 2061 | bool |
| 2062 | regex_search(_B, _B, match_results<_B, _A>&, const basic_regex<_C, _T>&, |
| 2063 | regex_constants::match_flag_type); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2064 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2065 | }; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2066 | |
| 2067 | template <class _CharT, class _Traits> |
| 2068 | basic_regex<_CharT, _Traits>::~basic_regex() |
| 2069 | { |
| 2070 | } |
| 2071 | |
| 2072 | template <class _CharT, class _Traits> |
| 2073 | template <class _ForwardIterator> |
| 2074 | void |
| 2075 | basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first, |
| 2076 | _ForwardIterator __last) |
| 2077 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2078 | { |
| 2079 | unique_ptr<__state> __h(new __end_state<_CharT>); |
| 2080 | __start_.reset(new __empty_state<_CharT>(__h.get())); |
| 2081 | __h.release(); |
| 2082 | __end_ = __start_.get(); |
| 2083 | } |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2084 | switch (__flags_ & 0x3F0) |
| 2085 | { |
| 2086 | case ECMAScript: |
| 2087 | break; |
| 2088 | case basic: |
| 2089 | __parse_basic_reg_exp(__first, __last); |
| 2090 | break; |
| 2091 | case extended: |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2092 | __parse_extended_reg_exp(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2093 | break; |
| 2094 | case awk: |
| 2095 | break; |
| 2096 | case grep: |
| 2097 | break; |
| 2098 | case egrep: |
| 2099 | break; |
| 2100 | default: |
| 2101 | throw regex_error(regex_constants::error_temp); |
| 2102 | } |
| 2103 | } |
| 2104 | |
| 2105 | template <class _CharT, class _Traits> |
| 2106 | template <class _ForwardIterator> |
| 2107 | _ForwardIterator |
| 2108 | basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first, |
| 2109 | _ForwardIterator __last) |
| 2110 | { |
| 2111 | if (__first != __last) |
| 2112 | { |
| 2113 | if (*__first == '^') |
| 2114 | { |
| 2115 | __push_l_anchor(); |
| 2116 | ++__first; |
| 2117 | } |
| 2118 | if (__first != __last) |
| 2119 | { |
| 2120 | __first = __parse_RE_expression(__first, __last); |
| 2121 | if (__first != __last) |
| 2122 | { |
| 2123 | _ForwardIterator __temp = next(__first); |
| 2124 | if (__temp == __last && *__first == '$') |
| 2125 | { |
| 2126 | __push_r_anchor(); |
| 2127 | ++__first; |
| 2128 | } |
| 2129 | } |
| 2130 | } |
| 2131 | if (__first != __last) |
| 2132 | throw regex_error(regex_constants::error_temp); |
| 2133 | } |
| 2134 | return __first; |
| 2135 | } |
| 2136 | |
| 2137 | template <class _CharT, class _Traits> |
| 2138 | template <class _ForwardIterator> |
| 2139 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2140 | basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first, |
| 2141 | _ForwardIterator __last) |
| 2142 | { |
| 2143 | while (true) |
| 2144 | { |
| 2145 | _ForwardIterator __temp = __parse_ERE_branch(__first, __last); |
| 2146 | if (__temp == __first) |
| 2147 | throw regex_error(regex_constants::error_temp); |
| 2148 | __first = __temp; |
| 2149 | if (__first == __last) |
| 2150 | break; |
| 2151 | if (*__first != '|') |
| 2152 | throw regex_error(regex_constants::error_temp); |
| 2153 | __push_alternation(); |
| 2154 | ++__first; |
| 2155 | } |
| 2156 | return __first; |
| 2157 | } |
| 2158 | |
| 2159 | template <class _CharT, class _Traits> |
| 2160 | template <class _ForwardIterator> |
| 2161 | _ForwardIterator |
| 2162 | basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first, |
| 2163 | _ForwardIterator __last) |
| 2164 | { |
| 2165 | _ForwardIterator __temp = __parse_ERE_expression(__first, __last); |
| 2166 | if (__temp == __first) |
| 2167 | throw regex_error(regex_constants::error_temp); |
| 2168 | do |
| 2169 | { |
| 2170 | __first = __temp; |
| 2171 | __temp = __parse_ERE_expression(__first, __last); |
| 2172 | } while (__temp != __first); |
| 2173 | return __first; |
| 2174 | } |
| 2175 | |
| 2176 | template <class _CharT, class _Traits> |
| 2177 | template <class _ForwardIterator> |
| 2178 | _ForwardIterator |
| 2179 | basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first, |
| 2180 | _ForwardIterator __last) |
| 2181 | { |
| 2182 | _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last); |
| 2183 | if (__temp == __first && __temp != __last) |
| 2184 | { |
| 2185 | switch (*__temp) |
| 2186 | { |
| 2187 | case '^': |
| 2188 | __push_l_anchor(); |
| 2189 | ++__temp; |
| 2190 | break; |
| 2191 | case '$': |
| 2192 | __push_r_anchor(); |
| 2193 | ++__temp; |
| 2194 | break; |
| 2195 | case '(': |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2196 | __push_begin_marked_subexpression(); |
| 2197 | unsigned __temp_count = __marked_count_; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2198 | ++__open_count_; |
| 2199 | __temp = __parse_extended_reg_exp(++__temp, __last); |
| 2200 | if (__temp == __last || *__temp != ')') |
| 2201 | throw regex_error(regex_constants::error_paren); |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2202 | __push_end_marked_subexpression(__temp_count); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2203 | --__open_count_; |
| 2204 | ++__temp; |
| 2205 | break; |
| 2206 | } |
| 2207 | } |
| 2208 | if (__temp != __first) |
| 2209 | __temp = __parse_ERE_dupl_symbol(__temp, __last); |
| 2210 | __first = __temp; |
| 2211 | return __first; |
| 2212 | } |
| 2213 | |
| 2214 | template <class _CharT, class _Traits> |
| 2215 | template <class _ForwardIterator> |
| 2216 | _ForwardIterator |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2217 | basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first, |
| 2218 | _ForwardIterator __last) |
| 2219 | { |
| 2220 | while (true) |
| 2221 | { |
| 2222 | _ForwardIterator __temp = __parse_simple_RE(__first, __last); |
| 2223 | if (__temp == __first) |
| 2224 | break; |
| 2225 | __first = __temp; |
| 2226 | } |
| 2227 | return __first; |
| 2228 | } |
| 2229 | |
| 2230 | template <class _CharT, class _Traits> |
| 2231 | template <class _ForwardIterator> |
| 2232 | _ForwardIterator |
| 2233 | basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first, |
| 2234 | _ForwardIterator __last) |
| 2235 | { |
| 2236 | if (__first != __last) |
| 2237 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2238 | __owns_one_state<_CharT>* __e = __end_; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame^] | 2239 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2240 | _ForwardIterator __temp = __parse_nondupl_RE(__first, __last); |
| 2241 | if (__temp != __first) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame^] | 2242 | __first = __parse_RE_dupl_symbol(__temp, __last, __e, |
| 2243 | __mexp_begin+1, __marked_count_+1); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2244 | } |
| 2245 | return __first; |
| 2246 | } |
| 2247 | |
| 2248 | template <class _CharT, class _Traits> |
| 2249 | template <class _ForwardIterator> |
| 2250 | _ForwardIterator |
| 2251 | basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first, |
| 2252 | _ForwardIterator __last) |
| 2253 | { |
| 2254 | _ForwardIterator __temp = __first; |
| 2255 | __first = __parse_one_char_or_coll_elem_RE(__first, __last); |
| 2256 | if (__temp == __first) |
| 2257 | { |
| 2258 | __temp = __parse_Back_open_paren(__first, __last); |
| 2259 | if (__temp != __first) |
| 2260 | { |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2261 | __push_begin_marked_subexpression(); |
| 2262 | unsigned __temp_count = __marked_count_; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2263 | __first = __parse_RE_expression(__temp, __last); |
| 2264 | __temp = __parse_Back_close_paren(__first, __last); |
| 2265 | if (__temp == __first) |
| 2266 | throw regex_error(regex_constants::error_paren); |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2267 | __push_end_marked_subexpression(__temp_count); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2268 | __first = __temp; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2269 | } |
| 2270 | else |
| 2271 | __first = __parse_BACKREF(__first, __last); |
| 2272 | } |
| 2273 | return __first; |
| 2274 | } |
| 2275 | |
| 2276 | template <class _CharT, class _Traits> |
| 2277 | template <class _ForwardIterator> |
| 2278 | _ForwardIterator |
| 2279 | basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE( |
| 2280 | _ForwardIterator __first, |
| 2281 | _ForwardIterator __last) |
| 2282 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2283 | _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2284 | if (__temp == __first) |
| 2285 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2286 | __temp = __parse_QUOTED_CHAR(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2287 | if (__temp == __first) |
| 2288 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2289 | if (__temp != __last && *__temp == '.') |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2290 | { |
| 2291 | __push_match_any(); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2292 | ++__temp; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2293 | } |
| 2294 | else |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2295 | __temp = __parse_bracket_expression(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2296 | } |
| 2297 | } |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2298 | __first = __temp; |
| 2299 | return __first; |
| 2300 | } |
| 2301 | |
| 2302 | template <class _CharT, class _Traits> |
| 2303 | template <class _ForwardIterator> |
| 2304 | _ForwardIterator |
| 2305 | basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE( |
| 2306 | _ForwardIterator __first, |
| 2307 | _ForwardIterator __last) |
| 2308 | { |
| 2309 | _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last); |
| 2310 | if (__temp == __first) |
| 2311 | { |
| 2312 | __temp = __parse_QUOTED_CHAR_ERE(__first, __last); |
| 2313 | if (__temp == __first) |
| 2314 | { |
| 2315 | if (__temp != __last && *__temp == '.') |
| 2316 | { |
| 2317 | __push_match_any(); |
| 2318 | ++__temp; |
| 2319 | } |
| 2320 | else |
| 2321 | __temp = __parse_bracket_expression(__first, __last); |
| 2322 | } |
| 2323 | } |
| 2324 | __first = __temp; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2325 | return __first; |
| 2326 | } |
| 2327 | |
| 2328 | template <class _CharT, class _Traits> |
| 2329 | template <class _ForwardIterator> |
| 2330 | _ForwardIterator |
| 2331 | basic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first, |
| 2332 | _ForwardIterator __last) |
| 2333 | { |
| 2334 | if (__first != __last) |
| 2335 | { |
| 2336 | _ForwardIterator __temp = next(__first); |
| 2337 | if (__temp != __last) |
| 2338 | { |
| 2339 | if (*__first == '\\' && *__temp == '(') |
| 2340 | __first = ++__temp; |
| 2341 | } |
| 2342 | } |
| 2343 | return __first; |
| 2344 | } |
| 2345 | |
| 2346 | template <class _CharT, class _Traits> |
| 2347 | template <class _ForwardIterator> |
| 2348 | _ForwardIterator |
| 2349 | basic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first, |
| 2350 | _ForwardIterator __last) |
| 2351 | { |
| 2352 | if (__first != __last) |
| 2353 | { |
| 2354 | _ForwardIterator __temp = next(__first); |
| 2355 | if (__temp != __last) |
| 2356 | { |
| 2357 | if (*__first == '\\' && *__temp == ')') |
| 2358 | __first = ++__temp; |
| 2359 | } |
| 2360 | } |
| 2361 | return __first; |
| 2362 | } |
| 2363 | |
| 2364 | template <class _CharT, class _Traits> |
| 2365 | template <class _ForwardIterator> |
| 2366 | _ForwardIterator |
| 2367 | basic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first, |
| 2368 | _ForwardIterator __last) |
| 2369 | { |
| 2370 | if (__first != __last) |
| 2371 | { |
| 2372 | _ForwardIterator __temp = next(__first); |
| 2373 | if (__temp != __last) |
| 2374 | { |
| 2375 | if (*__first == '\\' && *__temp == '{') |
| 2376 | __first = ++__temp; |
| 2377 | } |
| 2378 | } |
| 2379 | return __first; |
| 2380 | } |
| 2381 | |
| 2382 | template <class _CharT, class _Traits> |
| 2383 | template <class _ForwardIterator> |
| 2384 | _ForwardIterator |
| 2385 | basic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first, |
| 2386 | _ForwardIterator __last) |
| 2387 | { |
| 2388 | if (__first != __last) |
| 2389 | { |
| 2390 | _ForwardIterator __temp = next(__first); |
| 2391 | if (__temp != __last) |
| 2392 | { |
| 2393 | if (*__first == '\\' && *__temp == '}') |
| 2394 | __first = ++__temp; |
| 2395 | } |
| 2396 | } |
| 2397 | return __first; |
| 2398 | } |
| 2399 | |
| 2400 | template <class _CharT, class _Traits> |
| 2401 | template <class _ForwardIterator> |
| 2402 | _ForwardIterator |
| 2403 | basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first, |
| 2404 | _ForwardIterator __last) |
| 2405 | { |
| 2406 | if (__first != __last) |
| 2407 | { |
| 2408 | _ForwardIterator __temp = next(__first); |
| 2409 | if (__temp != __last) |
| 2410 | { |
| 2411 | if (*__first == '\\' && '1' <= *__temp && *__temp <= '9') |
| 2412 | { |
| 2413 | __push_back_ref(*__temp - '0'); |
| 2414 | __first = ++__temp; |
| 2415 | } |
| 2416 | } |
| 2417 | } |
| 2418 | return __first; |
| 2419 | } |
| 2420 | |
| 2421 | template <class _CharT, class _Traits> |
| 2422 | template <class _ForwardIterator> |
| 2423 | _ForwardIterator |
| 2424 | basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first, |
| 2425 | _ForwardIterator __last) |
| 2426 | { |
| 2427 | if (__first != __last) |
| 2428 | { |
| 2429 | _ForwardIterator __temp = next(__first); |
| 2430 | if (__temp == __last && *__first == '$') |
| 2431 | return __first; |
| 2432 | // Not called inside a bracket |
| 2433 | if (*__first == '.' || *__first == '\\' || *__first == '[') |
| 2434 | return __first; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2435 | __push_char(*__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2436 | ++__first; |
| 2437 | } |
| 2438 | return __first; |
| 2439 | } |
| 2440 | |
| 2441 | template <class _CharT, class _Traits> |
| 2442 | template <class _ForwardIterator> |
| 2443 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2444 | basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first, |
| 2445 | _ForwardIterator __last) |
| 2446 | { |
| 2447 | if (__first != __last) |
| 2448 | { |
| 2449 | switch (*__first) |
| 2450 | { |
| 2451 | case '^': |
| 2452 | case '.': |
| 2453 | case '[': |
| 2454 | case '$': |
| 2455 | case '(': |
| 2456 | case '|': |
| 2457 | case '*': |
| 2458 | case '+': |
| 2459 | case '?': |
| 2460 | case '{': |
| 2461 | case '\\': |
| 2462 | break; |
| 2463 | case ')': |
| 2464 | if (__open_count_ == 0) |
| 2465 | { |
| 2466 | __push_char(*__first); |
| 2467 | ++__first; |
| 2468 | } |
| 2469 | break; |
| 2470 | default: |
| 2471 | __push_char(*__first); |
| 2472 | ++__first; |
| 2473 | break; |
| 2474 | } |
| 2475 | } |
| 2476 | return __first; |
| 2477 | } |
| 2478 | |
| 2479 | template <class _CharT, class _Traits> |
| 2480 | template <class _ForwardIterator> |
| 2481 | _ForwardIterator |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2482 | basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first, |
| 2483 | _ForwardIterator __last) |
| 2484 | { |
| 2485 | if (__first != __last) |
| 2486 | { |
| 2487 | _ForwardIterator __temp = next(__first); |
| 2488 | if (__temp != __last) |
| 2489 | { |
| 2490 | if (*__first == '\\') |
| 2491 | { |
| 2492 | switch (*__temp) |
| 2493 | { |
| 2494 | case '^': |
| 2495 | case '.': |
| 2496 | case '*': |
| 2497 | case '[': |
| 2498 | case '$': |
| 2499 | case '\\': |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2500 | __push_char(*__temp); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2501 | __first = ++__temp; |
| 2502 | break; |
| 2503 | } |
| 2504 | } |
| 2505 | } |
| 2506 | } |
| 2507 | return __first; |
| 2508 | } |
| 2509 | |
| 2510 | template <class _CharT, class _Traits> |
| 2511 | template <class _ForwardIterator> |
| 2512 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2513 | basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first, |
| 2514 | _ForwardIterator __last) |
| 2515 | { |
| 2516 | if (__first != __last) |
| 2517 | { |
| 2518 | _ForwardIterator __temp = next(__first); |
| 2519 | if (__temp != __last) |
| 2520 | { |
| 2521 | if (*__first == '\\') |
| 2522 | { |
| 2523 | switch (*__temp) |
| 2524 | { |
| 2525 | case '^': |
| 2526 | case '.': |
| 2527 | case '*': |
| 2528 | case '[': |
| 2529 | case '$': |
| 2530 | case '\\': |
| 2531 | case '(': |
| 2532 | case ')': |
| 2533 | case '|': |
| 2534 | case '+': |
| 2535 | case '?': |
| 2536 | case '{': |
| 2537 | __push_char(*__temp); |
| 2538 | __first = ++__temp; |
| 2539 | break; |
| 2540 | } |
| 2541 | } |
| 2542 | } |
| 2543 | } |
| 2544 | return __first; |
| 2545 | } |
| 2546 | |
| 2547 | template <class _CharT, class _Traits> |
| 2548 | template <class _ForwardIterator> |
| 2549 | _ForwardIterator |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2550 | basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2551 | _ForwardIterator __last, |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame^] | 2552 | __owns_one_state<_CharT>* __s, |
| 2553 | unsigned __mexp_begin, |
| 2554 | unsigned __mexp_end) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2555 | { |
| 2556 | if (__first != __last) |
| 2557 | { |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2558 | if (*__first == '*') |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2559 | { |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame^] | 2560 | __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2561 | ++__first; |
| 2562 | } |
| 2563 | else |
| 2564 | { |
| 2565 | _ForwardIterator __temp = __parse_Back_open_brace(__first, __last); |
| 2566 | if (__temp != __first) |
| 2567 | { |
| 2568 | int __min = 0; |
| 2569 | __first = __temp; |
| 2570 | __temp = __parse_DUP_COUNT(__first, __last, __min); |
| 2571 | if (__temp == __first) |
| 2572 | throw regex_error(regex_constants::error_badbrace); |
| 2573 | __first = __temp; |
| 2574 | if (__first == __last) |
| 2575 | throw regex_error(regex_constants::error_brace); |
| 2576 | if (*__first != ',') |
| 2577 | { |
| 2578 | __temp = __parse_Back_close_brace(__first, __last); |
| 2579 | if (__temp == __first) |
| 2580 | throw regex_error(regex_constants::error_brace); |
| 2581 | __push_exact_repeat(__min); |
| 2582 | __first = __temp; |
| 2583 | } |
| 2584 | else |
| 2585 | { |
| 2586 | ++__first; // consume ',' |
| 2587 | int __max = -1; |
| 2588 | __first = __parse_DUP_COUNT(__first, __last, __max); |
| 2589 | __temp = __parse_Back_close_brace(__first, __last); |
| 2590 | if (__temp == __first) |
| 2591 | throw regex_error(regex_constants::error_brace); |
| 2592 | if (__max == -1) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame^] | 2593 | __push_greedy_inf_repeat(__min, __s, __mexp_end, __mexp_end); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2594 | else |
| 2595 | { |
| 2596 | if (__max < __min) |
| 2597 | throw regex_error(regex_constants::error_badbrace); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2598 | __push_loop(__min, __max, __s); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2599 | } |
| 2600 | __first = __temp; |
| 2601 | } |
| 2602 | } |
| 2603 | } |
| 2604 | } |
| 2605 | return __first; |
| 2606 | } |
| 2607 | |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2608 | template <class _CharT, class _Traits> |
| 2609 | template <class _ForwardIterator> |
| 2610 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2611 | basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first, |
| 2612 | _ForwardIterator __last) |
| 2613 | { |
| 2614 | if (__first != __last) |
| 2615 | { |
| 2616 | switch (*__first) |
| 2617 | { |
| 2618 | case '*': |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2619 | __push_greedy_inf_repeat(0, nullptr); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2620 | ++__first; |
| 2621 | break; |
| 2622 | case '+': |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2623 | __push_greedy_inf_repeat(1, 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_loop(0, 1, nullptr); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2628 | ++__first; |
| 2629 | break; |
| 2630 | case '{': |
| 2631 | { |
| 2632 | int __min; |
| 2633 | _ForwardIterator __temp = __parse_DUP_COUNT(__first, __last, __min); |
| 2634 | if (__temp == __first) |
| 2635 | throw regex_error(regex_constants::error_badbrace); |
| 2636 | __first = __temp; |
| 2637 | if (__first == __last) |
| 2638 | throw regex_error(regex_constants::error_brace); |
| 2639 | switch (*__first) |
| 2640 | { |
| 2641 | case '}': |
| 2642 | __push_exact_repeat(__min); |
| 2643 | ++__first; |
| 2644 | break; |
| 2645 | case ',': |
| 2646 | if (++__first == __last) |
| 2647 | throw regex_error(regex_constants::error_badbrace); |
| 2648 | if (*__first == '}') |
| 2649 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2650 | __push_greedy_inf_repeat(__min, nullptr); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2651 | ++__first; |
| 2652 | } |
| 2653 | else |
| 2654 | { |
| 2655 | int __max; |
| 2656 | __temp = __parse_DUP_COUNT(__first, __last, __max); |
| 2657 | if (__temp == __first) |
| 2658 | throw regex_error(regex_constants::error_brace); |
| 2659 | __first = __temp; |
| 2660 | if (__first == __last || *__first != '}') |
| 2661 | throw regex_error(regex_constants::error_brace); |
| 2662 | ++__first; |
| 2663 | if (__max < __min) |
| 2664 | throw regex_error(regex_constants::error_badbrace); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2665 | __push_loop(__min, __max, nullptr); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2666 | } |
| 2667 | default: |
| 2668 | throw regex_error(regex_constants::error_badbrace); |
| 2669 | } |
| 2670 | } |
| 2671 | break; |
| 2672 | } |
| 2673 | } |
| 2674 | return __first; |
| 2675 | } |
| 2676 | |
| 2677 | template <class _CharT, class _Traits> |
| 2678 | template <class _ForwardIterator> |
| 2679 | _ForwardIterator |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2680 | basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first, |
| 2681 | _ForwardIterator __last) |
| 2682 | { |
| 2683 | if (__first != __last && *__first == '[') |
| 2684 | { |
| 2685 | if (++__first == __last) |
| 2686 | throw regex_error(regex_constants::error_brack); |
| 2687 | bool __non_matching = false; |
| 2688 | if (*__first == '^') |
| 2689 | { |
| 2690 | ++__first; |
| 2691 | __non_matching = true; |
| 2692 | __start_nonmatching_list(); |
| 2693 | } |
| 2694 | else |
| 2695 | __start_matching_list(); |
| 2696 | if (__first == __last) |
| 2697 | throw regex_error(regex_constants::error_brack); |
| 2698 | if (*__first == ']') |
| 2699 | { |
| 2700 | __push_char(']'); |
| 2701 | ++__first; |
| 2702 | } |
| 2703 | __first = __parse_follow_list(__first, __last); |
| 2704 | if (__first == __last) |
| 2705 | throw regex_error(regex_constants::error_brack); |
| 2706 | if (*__first == '-') |
| 2707 | { |
| 2708 | __push_char('-'); |
| 2709 | ++__first; |
| 2710 | } |
| 2711 | if (__first == __last || *__first != ']') |
| 2712 | throw regex_error(regex_constants::error_brack); |
| 2713 | if (__non_matching) |
| 2714 | __end_nonmatching_list(); |
| 2715 | else |
| 2716 | __end_matching_list(); |
| 2717 | ++__first; |
| 2718 | } |
| 2719 | return __first; |
| 2720 | } |
| 2721 | |
| 2722 | template <class _CharT, class _Traits> |
| 2723 | template <class _ForwardIterator> |
| 2724 | _ForwardIterator |
| 2725 | basic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first, |
| 2726 | _ForwardIterator __last) |
| 2727 | { |
| 2728 | if (__first != __last) |
| 2729 | { |
| 2730 | while (true) |
| 2731 | { |
| 2732 | _ForwardIterator __temp = __parse_expression_term(__first, __last); |
| 2733 | if (__temp == __first) |
| 2734 | break; |
| 2735 | __first = __temp; |
| 2736 | } |
| 2737 | } |
| 2738 | return __first; |
| 2739 | } |
| 2740 | |
| 2741 | template <class _CharT, class _Traits> |
| 2742 | template <class _ForwardIterator> |
| 2743 | _ForwardIterator |
| 2744 | basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first, |
| 2745 | _ForwardIterator __last) |
| 2746 | { |
| 2747 | if (__first != __last && *__first != ']') |
| 2748 | { |
| 2749 | bool __parsed_one = false; |
| 2750 | _ForwardIterator __temp = next(__first); |
| 2751 | if (__temp != __last && *__first == '[') |
| 2752 | { |
| 2753 | if (*__temp == '=') |
| 2754 | return __parse_equivalence_class(++__temp, __last); |
| 2755 | else if (*__temp == ':') |
| 2756 | return __parse_character_class(++__temp, __last); |
| 2757 | else if (*__temp == '.') |
| 2758 | { |
| 2759 | __first = __parse_collating_symbol(++__temp, __last); |
| 2760 | __parsed_one = true; |
| 2761 | } |
| 2762 | } |
| 2763 | if (!__parsed_one) |
| 2764 | { |
| 2765 | __push_char(*__first); |
| 2766 | ++__first; |
| 2767 | } |
| 2768 | if (__first != __last && *__first != ']') |
| 2769 | { |
| 2770 | __temp = next(__first); |
| 2771 | if (__temp != __last && *__first == '-' && *__temp != ']') |
| 2772 | { |
| 2773 | // parse a range |
| 2774 | __first = __temp; |
| 2775 | ++__temp; |
| 2776 | if (__temp != __last && *__first == '[' && *__temp == '.') |
| 2777 | __first = __parse_collating_symbol(++__temp, __last); |
| 2778 | else |
| 2779 | { |
| 2780 | __push_char(*__first); |
| 2781 | ++__first; |
| 2782 | } |
| 2783 | __push_range(); |
| 2784 | } |
| 2785 | } |
| 2786 | } |
| 2787 | return __first; |
| 2788 | } |
| 2789 | |
| 2790 | template <class _CharT, class _Traits> |
| 2791 | template <class _ForwardIterator> |
| 2792 | _ForwardIterator |
| 2793 | basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first, |
| 2794 | _ForwardIterator __last) |
| 2795 | { |
| 2796 | // Found [= |
| 2797 | // This means =] must exist |
| 2798 | value_type _Equal_close[2] = {'=', ']'}; |
| 2799 | _ForwardIterator __temp = _STD::search(__first, __last, _Equal_close, |
| 2800 | _Equal_close+2); |
| 2801 | if (__temp == __last) |
| 2802 | throw regex_error(regex_constants::error_brack); |
| 2803 | // [__first, __temp) contains all text in [= ... =] |
| 2804 | typedef typename _Traits::string_type string_type; |
| 2805 | string_type __collate_name = |
| 2806 | __traits_.lookup_collatename(__first, __temp); |
| 2807 | if (__collate_name.empty()) |
| 2808 | throw regex_error(regex_constants::error_brack); |
| 2809 | string_type __equiv_name = |
| 2810 | __traits_.transform_primary(__collate_name.begin(), |
| 2811 | __collate_name.end()); |
| 2812 | if (!__equiv_name.empty()) |
| 2813 | __push_char(__equiv_name); |
| 2814 | else |
| 2815 | __push_char(__collate_name); |
| 2816 | __first = next(__temp, 2); |
| 2817 | return __first; |
| 2818 | } |
| 2819 | |
| 2820 | template <class _CharT, class _Traits> |
| 2821 | template <class _ForwardIterator> |
| 2822 | _ForwardIterator |
| 2823 | basic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first, |
| 2824 | _ForwardIterator __last) |
| 2825 | { |
| 2826 | // Found [: |
| 2827 | // This means :] must exist |
| 2828 | value_type _Colon_close[2] = {':', ']'}; |
| 2829 | _ForwardIterator __temp = _STD::search(__first, __last, _Colon_close, |
| 2830 | _Colon_close+2); |
| 2831 | if (__temp == __last) |
| 2832 | throw regex_error(regex_constants::error_brack); |
| 2833 | // [__first, __temp) contains all text in [: ... :] |
| 2834 | typedef typename _Traits::char_class_type char_class_type; |
| 2835 | char_class_type __class_type = |
| 2836 | __traits_.lookup_classname(__first, __temp, __flags_ & icase); |
| 2837 | if (__class_type == 0) |
| 2838 | throw regex_error(regex_constants::error_brack); |
| 2839 | __push_class_type(__class_type); |
| 2840 | __first = next(__temp, 2); |
| 2841 | return __first; |
| 2842 | } |
| 2843 | |
| 2844 | template <class _CharT, class _Traits> |
| 2845 | template <class _ForwardIterator> |
| 2846 | _ForwardIterator |
| 2847 | basic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first, |
| 2848 | _ForwardIterator __last) |
| 2849 | { |
| 2850 | // Found [. |
| 2851 | // This means .] must exist |
| 2852 | value_type _Dot_close[2] = {'.', ']'}; |
| 2853 | _ForwardIterator __temp = _STD::search(__first, __last, _Dot_close, |
| 2854 | _Dot_close+2); |
| 2855 | if (__temp == __last) |
| 2856 | throw regex_error(regex_constants::error_brack); |
| 2857 | // [__first, __temp) contains all text in [. ... .] |
| 2858 | typedef typename _Traits::string_type string_type; |
| 2859 | string_type __collate_name = |
| 2860 | __traits_.lookup_collatename(__first, __temp); |
| 2861 | if (__collate_name.empty()) |
| 2862 | throw regex_error(regex_constants::error_brack); |
| 2863 | __push_char(__collate_name); |
| 2864 | __first = next(__temp, 2); |
| 2865 | return __first; |
| 2866 | } |
| 2867 | |
| 2868 | template <class _CharT, class _Traits> |
| 2869 | template <class _ForwardIterator> |
| 2870 | _ForwardIterator |
| 2871 | basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first, |
| 2872 | _ForwardIterator __last, |
| 2873 | int& __c) |
| 2874 | { |
| 2875 | if (__first != __last && '0' <= *__first && *__first <= '9') |
| 2876 | { |
| 2877 | __c = *__first - '0'; |
| 2878 | for (++__first; __first != __last && '0' <= *__first && *__first <= '9'; |
| 2879 | ++__first) |
| 2880 | { |
| 2881 | __c *= 10; |
| 2882 | __c += *__first - '0'; |
| 2883 | } |
| 2884 | } |
| 2885 | return __first; |
| 2886 | } |
| 2887 | |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2888 | template <class _CharT, class _Traits> |
| 2889 | void |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2890 | basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max, |
| 2891 | __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end, |
| 2892 | bool __greedy) |
| 2893 | { |
| 2894 | unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first())); |
| 2895 | __end_->first() = nullptr; |
| 2896 | unique_ptr<__loop<_CharT> > __e2; |
| 2897 | if (__mexp_begin != __mexp_end) |
| 2898 | { |
| 2899 | unique_ptr<__zero_marked_exprs<_CharT> > |
| 2900 | __e3(new __zero_marked_exprs<_CharT>(__mexp_begin, __mexp_end, |
| 2901 | __s->first())); |
| 2902 | __s->first() = nullptr; |
| 2903 | __e2.reset(new __loop<_CharT>(__loop_count_, __e3.get(), __e1.get(), |
| 2904 | __greedy, __min, __max)); |
| 2905 | __e3.release(); |
| 2906 | __e1.release(); |
| 2907 | } |
| 2908 | else |
| 2909 | { |
| 2910 | __e2.reset(new __loop<_CharT>(__loop_count_, __s->first(), __e1.get(), |
| 2911 | __greedy, __min, __max)); |
| 2912 | __s->first() = nullptr; |
| 2913 | __e1.release(); |
| 2914 | } |
| 2915 | __end_->first() = new __increment_loop_count<_CharT>(__loop_count_, __e2.get()); |
| 2916 | __end_ = __e2->second(); |
| 2917 | __s->first() = new __zero_loop_count<_CharT>(__loop_count_, __e2.get()); |
| 2918 | __e2.release(); |
| 2919 | ++__loop_count_; |
| 2920 | } |
| 2921 | |
| 2922 | template <class _CharT, class _Traits> |
| 2923 | void |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2924 | basic_regex<_CharT, _Traits>::__push_char(value_type __c) |
| 2925 | { |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame^] | 2926 | __end_->first() = new __match_char<_CharT>(__c, __end_->first()); |
| 2927 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2928 | } |
| 2929 | |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2930 | template <class _CharT, class _Traits> |
| 2931 | void |
| 2932 | basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression() |
| 2933 | { |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame^] | 2934 | __end_->first() = new __begin_marked_subexpression<_CharT>(++__marked_count_, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2935 | __end_->first()); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame^] | 2936 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2937 | } |
| 2938 | |
| 2939 | template <class _CharT, class _Traits> |
| 2940 | void |
| 2941 | basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub) |
| 2942 | { |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame^] | 2943 | __end_->first() = new __end_marked_subexpression<_CharT>(__sub, |
| 2944 | __end_->first()); |
| 2945 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2946 | } |
| 2947 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2948 | typedef basic_regex<char> regex; |
| 2949 | typedef basic_regex<wchar_t> wregex; |
| 2950 | |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2951 | // sub_match |
| 2952 | |
| 2953 | template <class _BidirectionalIterator> |
| 2954 | class sub_match |
| 2955 | : public pair<_BidirectionalIterator, _BidirectionalIterator> |
| 2956 | { |
| 2957 | public: |
| 2958 | typedef _BidirectionalIterator iterator; |
| 2959 | typedef typename iterator_traits<iterator>::value_type value_type; |
| 2960 | typedef typename iterator_traits<iterator>::difference_type difference_type; |
| 2961 | typedef basic_string<value_type> string_type; |
| 2962 | |
| 2963 | bool matched; |
| 2964 | |
| 2965 | difference_type length() const |
| 2966 | {return matched ? _STD::distance(this->first, this->second) : 0;} |
| 2967 | string_type str() const |
| 2968 | {return matched ? string_type(this->first, this->second) : string_type();} |
| 2969 | operator string_type() const |
| 2970 | {return str();} |
| 2971 | |
| 2972 | int compare(const sub_match& __s) const |
| 2973 | {return str().compare(__s.str());} |
| 2974 | int compare(const string_type& __s) const |
| 2975 | {return str().compare(__s);} |
| 2976 | int compare(const value_type* __s) const |
| 2977 | {return str().compare(__s);} |
| 2978 | }; |
| 2979 | |
| 2980 | typedef sub_match<const char*> csub_match; |
| 2981 | typedef sub_match<const wchar_t*> wcsub_match; |
| 2982 | typedef sub_match<string::const_iterator> ssub_match; |
| 2983 | typedef sub_match<wstring::const_iterator> wssub_match; |
| 2984 | |
| 2985 | template <class _BiIter> |
| 2986 | inline _LIBCPP_INLINE_VISIBILITY |
| 2987 | bool |
| 2988 | operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 2989 | { |
| 2990 | return __x.compare(__y) == 0; |
| 2991 | } |
| 2992 | |
| 2993 | template <class _BiIter> |
| 2994 | inline _LIBCPP_INLINE_VISIBILITY |
| 2995 | bool |
| 2996 | operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 2997 | { |
| 2998 | return !(__x == __y); |
| 2999 | } |
| 3000 | |
| 3001 | template <class _BiIter> |
| 3002 | inline _LIBCPP_INLINE_VISIBILITY |
| 3003 | bool |
| 3004 | operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 3005 | { |
| 3006 | return __x.compare(__y) < 0; |
| 3007 | } |
| 3008 | |
| 3009 | template <class _BiIter> |
| 3010 | inline _LIBCPP_INLINE_VISIBILITY |
| 3011 | bool |
| 3012 | operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 3013 | { |
| 3014 | return !(__y < __x); |
| 3015 | } |
| 3016 | |
| 3017 | template <class _BiIter> |
| 3018 | inline _LIBCPP_INLINE_VISIBILITY |
| 3019 | bool |
| 3020 | operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 3021 | { |
| 3022 | return !(__x < __y); |
| 3023 | } |
| 3024 | |
| 3025 | template <class _BiIter> |
| 3026 | inline _LIBCPP_INLINE_VISIBILITY |
| 3027 | bool |
| 3028 | operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 3029 | { |
| 3030 | return __y < __x; |
| 3031 | } |
| 3032 | |
| 3033 | template <class _BiIter, class _ST, class _SA> |
| 3034 | inline _LIBCPP_INLINE_VISIBILITY |
| 3035 | bool |
| 3036 | operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 3037 | const sub_match<_BiIter>& __y) |
| 3038 | { |
| 3039 | return __y.compare(__x.c_str()) == 0; |
| 3040 | } |
| 3041 | |
| 3042 | template <class _BiIter, class _ST, class _SA> |
| 3043 | inline _LIBCPP_INLINE_VISIBILITY |
| 3044 | bool |
| 3045 | operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 3046 | const sub_match<_BiIter>& __y) |
| 3047 | { |
| 3048 | return !(__x == __y); |
| 3049 | } |
| 3050 | |
| 3051 | template <class _BiIter, class _ST, class _SA> |
| 3052 | inline _LIBCPP_INLINE_VISIBILITY |
| 3053 | bool |
| 3054 | operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 3055 | const sub_match<_BiIter>& __y) |
| 3056 | { |
| 3057 | return __y.compare(__x.c_str()) > 0; |
| 3058 | } |
| 3059 | |
| 3060 | template <class _BiIter, class _ST, class _SA> |
| 3061 | inline _LIBCPP_INLINE_VISIBILITY |
| 3062 | bool |
| 3063 | operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 3064 | const sub_match<_BiIter>& __y) |
| 3065 | { |
| 3066 | return __y < __x; |
| 3067 | } |
| 3068 | |
| 3069 | template <class _BiIter, class _ST, class _SA> |
| 3070 | inline _LIBCPP_INLINE_VISIBILITY |
| 3071 | bool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 3072 | const sub_match<_BiIter>& __y) |
| 3073 | { |
| 3074 | return !(__x < __y); |
| 3075 | } |
| 3076 | |
| 3077 | template <class _BiIter, class _ST, class _SA> |
| 3078 | inline _LIBCPP_INLINE_VISIBILITY |
| 3079 | bool |
| 3080 | operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 3081 | const sub_match<_BiIter>& __y) |
| 3082 | { |
| 3083 | return !(__y < __x); |
| 3084 | } |
| 3085 | |
| 3086 | template <class _BiIter, class _ST, class _SA> |
| 3087 | inline _LIBCPP_INLINE_VISIBILITY |
| 3088 | bool |
| 3089 | operator==(const sub_match<_BiIter>& __x, |
| 3090 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 3091 | { |
| 3092 | return __x.compare(__y.c_str()) == 0; |
| 3093 | } |
| 3094 | |
| 3095 | template <class _BiIter, class _ST, class _SA> |
| 3096 | inline _LIBCPP_INLINE_VISIBILITY |
| 3097 | bool |
| 3098 | operator!=(const sub_match<_BiIter>& __x, |
| 3099 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 3100 | { |
| 3101 | return !(__x == __y); |
| 3102 | } |
| 3103 | |
| 3104 | template <class _BiIter, class _ST, class _SA> |
| 3105 | inline _LIBCPP_INLINE_VISIBILITY |
| 3106 | bool |
| 3107 | operator<(const sub_match<_BiIter>& __x, |
| 3108 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 3109 | { |
| 3110 | return __x.compare(__y.c_str()) < 0; |
| 3111 | } |
| 3112 | |
| 3113 | template <class _BiIter, class _ST, class _SA> |
| 3114 | inline _LIBCPP_INLINE_VISIBILITY |
| 3115 | bool operator>(const sub_match<_BiIter>& __x, |
| 3116 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 3117 | { |
| 3118 | return __y < __x; |
| 3119 | } |
| 3120 | |
| 3121 | template <class _BiIter, class _ST, class _SA> |
| 3122 | inline _LIBCPP_INLINE_VISIBILITY |
| 3123 | bool |
| 3124 | operator>=(const sub_match<_BiIter>& __x, |
| 3125 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 3126 | { |
| 3127 | return !(__x < __y); |
| 3128 | } |
| 3129 | |
| 3130 | template <class _BiIter, class _ST, class _SA> |
| 3131 | inline _LIBCPP_INLINE_VISIBILITY |
| 3132 | bool |
| 3133 | operator<=(const sub_match<_BiIter>& __x, |
| 3134 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 3135 | { |
| 3136 | return !(__y < __x); |
| 3137 | } |
| 3138 | |
| 3139 | template <class _BiIter> |
| 3140 | inline _LIBCPP_INLINE_VISIBILITY |
| 3141 | bool |
| 3142 | operator==(typename iterator_traits<_BiIter>::value_type const* __x, |
| 3143 | const sub_match<_BiIter>& __y) |
| 3144 | { |
| 3145 | return __y.compare(__x) == 0; |
| 3146 | } |
| 3147 | |
| 3148 | template <class _BiIter> |
| 3149 | inline _LIBCPP_INLINE_VISIBILITY |
| 3150 | bool |
| 3151 | operator!=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 3152 | const sub_match<_BiIter>& __y) |
| 3153 | { |
| 3154 | return !(__x == __y); |
| 3155 | } |
| 3156 | |
| 3157 | template <class _BiIter> |
| 3158 | inline _LIBCPP_INLINE_VISIBILITY |
| 3159 | bool |
| 3160 | operator<(typename iterator_traits<_BiIter>::value_type const* __x, |
| 3161 | const sub_match<_BiIter>& __y) |
| 3162 | { |
| 3163 | return __y.compare(__x) > 0; |
| 3164 | } |
| 3165 | |
| 3166 | template <class _BiIter> |
| 3167 | inline _LIBCPP_INLINE_VISIBILITY |
| 3168 | bool |
| 3169 | operator>(typename iterator_traits<_BiIter>::value_type const* __x, |
| 3170 | const sub_match<_BiIter>& __y) |
| 3171 | { |
| 3172 | return __y < __x; |
| 3173 | } |
| 3174 | |
| 3175 | template <class _BiIter> |
| 3176 | inline _LIBCPP_INLINE_VISIBILITY |
| 3177 | bool |
| 3178 | operator>=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 3179 | const sub_match<_BiIter>& __y) |
| 3180 | { |
| 3181 | return !(__x < __y); |
| 3182 | } |
| 3183 | |
| 3184 | template <class _BiIter> |
| 3185 | inline _LIBCPP_INLINE_VISIBILITY |
| 3186 | bool |
| 3187 | operator<=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 3188 | const sub_match<_BiIter>& __y) |
| 3189 | { |
| 3190 | return !(__y < __x); |
| 3191 | } |
| 3192 | |
| 3193 | template <class _BiIter> |
| 3194 | inline _LIBCPP_INLINE_VISIBILITY |
| 3195 | bool |
| 3196 | operator==(const sub_match<_BiIter>& __x, |
| 3197 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 3198 | { |
| 3199 | return __x.compare(__y) == 0; |
| 3200 | } |
| 3201 | |
| 3202 | template <class _BiIter> |
| 3203 | inline _LIBCPP_INLINE_VISIBILITY |
| 3204 | bool |
| 3205 | operator!=(const sub_match<_BiIter>& __x, |
| 3206 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 3207 | { |
| 3208 | return !(__x == __y); |
| 3209 | } |
| 3210 | |
| 3211 | template <class _BiIter> |
| 3212 | inline _LIBCPP_INLINE_VISIBILITY |
| 3213 | bool |
| 3214 | operator<(const sub_match<_BiIter>& __x, |
| 3215 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 3216 | { |
| 3217 | return __x.compare(__y) < 0; |
| 3218 | } |
| 3219 | |
| 3220 | template <class _BiIter> |
| 3221 | inline _LIBCPP_INLINE_VISIBILITY |
| 3222 | bool |
| 3223 | operator>(const sub_match<_BiIter>& __x, |
| 3224 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 3225 | { |
| 3226 | return __y < __x; |
| 3227 | } |
| 3228 | |
| 3229 | template <class _BiIter> |
| 3230 | inline _LIBCPP_INLINE_VISIBILITY |
| 3231 | bool |
| 3232 | operator>=(const sub_match<_BiIter>& __x, |
| 3233 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 3234 | { |
| 3235 | return !(__x < __y); |
| 3236 | } |
| 3237 | |
| 3238 | template <class _BiIter> |
| 3239 | inline _LIBCPP_INLINE_VISIBILITY |
| 3240 | bool |
| 3241 | operator<=(const sub_match<_BiIter>& __x, |
| 3242 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 3243 | { |
| 3244 | return !(__y < __x); |
| 3245 | } |
| 3246 | |
| 3247 | template <class _BiIter> |
| 3248 | inline _LIBCPP_INLINE_VISIBILITY |
| 3249 | bool |
| 3250 | operator==(typename iterator_traits<_BiIter>::value_type const& __x, |
| 3251 | const sub_match<_BiIter>& __y) |
| 3252 | { |
| 3253 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 3254 | return __y.compare(string_type(1, __x)) == 0; |
| 3255 | } |
| 3256 | |
| 3257 | template <class _BiIter> |
| 3258 | inline _LIBCPP_INLINE_VISIBILITY |
| 3259 | bool |
| 3260 | operator!=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 3261 | const sub_match<_BiIter>& __y) |
| 3262 | { |
| 3263 | return !(__x == __y); |
| 3264 | } |
| 3265 | |
| 3266 | template <class _BiIter> |
| 3267 | inline _LIBCPP_INLINE_VISIBILITY |
| 3268 | bool |
| 3269 | operator<(typename iterator_traits<_BiIter>::value_type const& __x, |
| 3270 | const sub_match<_BiIter>& __y) |
| 3271 | { |
| 3272 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 3273 | return __y.compare(string_type(1, __x)) > 0; |
| 3274 | } |
| 3275 | |
| 3276 | template <class _BiIter> |
| 3277 | inline _LIBCPP_INLINE_VISIBILITY |
| 3278 | bool |
| 3279 | operator>(typename iterator_traits<_BiIter>::value_type const& __x, |
| 3280 | const sub_match<_BiIter>& __y) |
| 3281 | { |
| 3282 | return __y < __x; |
| 3283 | } |
| 3284 | |
| 3285 | template <class _BiIter> |
| 3286 | inline _LIBCPP_INLINE_VISIBILITY |
| 3287 | bool |
| 3288 | operator>=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 3289 | const sub_match<_BiIter>& __y) |
| 3290 | { |
| 3291 | return !(__x < __y); |
| 3292 | } |
| 3293 | |
| 3294 | template <class _BiIter> |
| 3295 | inline _LIBCPP_INLINE_VISIBILITY |
| 3296 | bool |
| 3297 | operator<=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 3298 | const sub_match<_BiIter>& __y) |
| 3299 | { |
| 3300 | return !(__y < __x); |
| 3301 | } |
| 3302 | |
| 3303 | template <class _BiIter> |
| 3304 | inline _LIBCPP_INLINE_VISIBILITY |
| 3305 | bool |
| 3306 | operator==(const sub_match<_BiIter>& __x, |
| 3307 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 3308 | { |
| 3309 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 3310 | return __x.compare(string_type(1, __y)) == 0; |
| 3311 | } |
| 3312 | |
| 3313 | template <class _BiIter> |
| 3314 | inline _LIBCPP_INLINE_VISIBILITY |
| 3315 | bool |
| 3316 | operator!=(const sub_match<_BiIter>& __x, |
| 3317 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 3318 | { |
| 3319 | return !(__x == __y); |
| 3320 | } |
| 3321 | |
| 3322 | template <class _BiIter> |
| 3323 | inline _LIBCPP_INLINE_VISIBILITY |
| 3324 | bool |
| 3325 | operator<(const sub_match<_BiIter>& __x, |
| 3326 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 3327 | { |
| 3328 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 3329 | return __x.compare(string_type(1, __y)) < 0; |
| 3330 | } |
| 3331 | |
| 3332 | template <class _BiIter> |
| 3333 | inline _LIBCPP_INLINE_VISIBILITY |
| 3334 | bool |
| 3335 | operator>(const sub_match<_BiIter>& __x, |
| 3336 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 3337 | { |
| 3338 | return __y < __x; |
| 3339 | } |
| 3340 | |
| 3341 | template <class _BiIter> |
| 3342 | inline _LIBCPP_INLINE_VISIBILITY |
| 3343 | bool |
| 3344 | operator>=(const sub_match<_BiIter>& __x, |
| 3345 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 3346 | { |
| 3347 | return !(__x < __y); |
| 3348 | } |
| 3349 | |
| 3350 | template <class _BiIter> |
| 3351 | inline _LIBCPP_INLINE_VISIBILITY |
| 3352 | bool |
| 3353 | operator<=(const sub_match<_BiIter>& __x, |
| 3354 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 3355 | { |
| 3356 | return !(__y < __x); |
| 3357 | } |
| 3358 | |
| 3359 | template <class _CharT, class _ST, class _BiIter> |
| 3360 | inline _LIBCPP_INLINE_VISIBILITY |
| 3361 | basic_ostream<_CharT, _ST>& |
| 3362 | operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m) |
| 3363 | { |
| 3364 | return __os << __m.str(); |
| 3365 | } |
| 3366 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 3367 | template <class _BidirectionalIterator, |
| 3368 | class _Allocator = allocator<sub_match<_BidirectionalIterator> > > |
| 3369 | class match_results |
| 3370 | { |
| 3371 | public: |
| 3372 | typedef _Allocator allocator_type; |
| 3373 | typedef sub_match<_BidirectionalIterator> value_type; |
| 3374 | private: |
| 3375 | typedef vector<value_type, allocator_type> __container_type; |
| 3376 | |
| 3377 | __container_type __matches_; |
| 3378 | value_type __unmatched_; |
| 3379 | value_type __prefix_; |
| 3380 | value_type __suffix_; |
| 3381 | public: |
| 3382 | typedef const value_type& const_reference; |
| 3383 | typedef const_reference reference; |
| 3384 | typedef typename __container_type::const_iterator const_iterator; |
| 3385 | typedef const_iterator iterator; |
| 3386 | typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; |
| 3387 | typedef typename allocator_traits<allocator_type>::size_type size_type; |
| 3388 | typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type; |
| 3389 | typedef basic_string<char_type> string_type; |
| 3390 | |
| 3391 | // construct/copy/destroy: |
| 3392 | explicit match_results(const allocator_type& __a = allocator_type()); |
| 3393 | // match_results(const match_results&) = default; |
| 3394 | // match_results& operator=(const match_results&) = default; |
| 3395 | #ifdef _LIBCPP_MOVE |
| 3396 | // match_results(match_results&& __m) = default; |
| 3397 | // match_results& operator=(match_results&& __m) = default; |
| 3398 | #endif |
| 3399 | // ~match_results() = default; |
| 3400 | |
| 3401 | // size: |
| 3402 | size_type size() const {return __matches_.size();} |
| 3403 | size_type max_size() const {return __matches_.max_size();} |
| 3404 | bool empty() const {return size() == 0;} |
| 3405 | |
| 3406 | // element access: |
| 3407 | difference_type length(size_type __sub = 0) const |
| 3408 | {return (*this)[__sub].length();} |
| 3409 | difference_type position(size_type __sub = 0) const |
| 3410 | {return _STD::distance(__prefix_.first, (*this)[__sub].first);} |
| 3411 | string_type str(size_type __sub = 0) const |
| 3412 | {return (*this)[__sub].str();} |
| 3413 | const_reference operator[](size_type __n) const |
| 3414 | {return __n < __matches_.size() ? __matches_[__n] : __unmatched_;} |
| 3415 | |
| 3416 | const_reference prefix() const {return __prefix_;} |
| 3417 | const_reference suffix() const {return __suffix_;} |
| 3418 | |
| 3419 | const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin() + 1;} |
| 3420 | const_iterator end() const {return __matches_.end();} |
| 3421 | const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin() + 1;} |
| 3422 | const_iterator cend() const {return __matches_.end();} |
| 3423 | |
| 3424 | // format: |
| 3425 | template <class _OutputIter> |
| 3426 | _OutputIter |
| 3427 | format(_OutputIter __out, const char_type* __fmt_first, |
| 3428 | const char_type* __fmt_last, |
| 3429 | regex_constants::match_flag_type __flags = regex_constants::format_default) const; |
| 3430 | template <class _OutputIter, class _ST, class _SA> |
| 3431 | _OutputIter |
| 3432 | format(_OutputIter __out, const basic_string<char_type, _ST, _SA>& __fmt, |
| 3433 | regex_constants::match_flag_type __flags = regex_constants::format_default) const; |
| 3434 | template <class _ST, class _SA> |
| 3435 | basic_string<char_type, _ST, _SA> |
| 3436 | format(const basic_string<char_type, _ST, _SA>& __fmt, |
| 3437 | regex_constants::match_flag_type __flags = regex_constants::format_default) const; |
| 3438 | string_type |
| 3439 | format(const char_type* __fmt, |
| 3440 | regex_constants::match_flag_type __flags = regex_constants::format_default) const; |
| 3441 | |
| 3442 | // allocator: |
| 3443 | allocator_type get_allocator() const {return __matches_.get_allocator();} |
| 3444 | |
| 3445 | // swap: |
| 3446 | void swap(match_results& __m); |
| 3447 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3448 | private: |
| 3449 | void __init(unsigned __s, |
| 3450 | _BidirectionalIterator __f, _BidirectionalIterator __l); |
| 3451 | |
| 3452 | template <class, class> friend class basic_regex; |
| 3453 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 3454 | template <class _B, class _A, class _C, class _T> |
| 3455 | friend |
| 3456 | bool |
| 3457 | regex_match(_B, _B, match_results<_B, _A>&, const basic_regex<_C, _T>&, |
| 3458 | regex_constants::match_flag_type); |
| 3459 | }; |
| 3460 | |
| 3461 | template <class _BidirectionalIterator, class _Allocator> |
| 3462 | match_results<_BidirectionalIterator, _Allocator>::match_results( |
| 3463 | const allocator_type& __a) |
| 3464 | : __matches_(__a), |
| 3465 | __unmatched_(), |
| 3466 | __prefix_(), |
| 3467 | __suffix_() |
| 3468 | { |
| 3469 | } |
| 3470 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3471 | template <class _BidirectionalIterator, class _Allocator> |
| 3472 | void |
| 3473 | match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s, |
| 3474 | _BidirectionalIterator __f, _BidirectionalIterator __l) |
| 3475 | { |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3476 | __unmatched_.first = __l; |
| 3477 | __unmatched_.second = __l; |
| 3478 | __unmatched_.matched = false; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3479 | __matches_.assign(__s, __unmatched_); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3480 | __prefix_.first = __f; |
| 3481 | __prefix_.second = __f; |
| 3482 | __prefix_.matched = false; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame^] | 3483 | __suffix_ = __unmatched_; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3484 | } |
| 3485 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 3486 | typedef match_results<const char*> cmatch; |
| 3487 | typedef match_results<const wchar_t*> wcmatch; |
| 3488 | typedef match_results<string::const_iterator> smatch; |
| 3489 | typedef match_results<wstring::const_iterator> wsmatch; |
| 3490 | |
| 3491 | template <class _BidirectionalIterator, class _Allocator> |
| 3492 | bool |
| 3493 | operator==(const match_results<_BidirectionalIterator, _Allocator>& __x, |
| 3494 | const match_results<_BidirectionalIterator, _Allocator>& __y); |
| 3495 | |
| 3496 | template <class _BidirectionalIterator, class _Allocator> |
| 3497 | bool |
| 3498 | operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x, |
| 3499 | const match_results<_BidirectionalIterator, _Allocator>& __y); |
| 3500 | |
| 3501 | template <class _BidirectionalIterator, class _Allocator> |
| 3502 | void |
| 3503 | swap(match_results<_BidirectionalIterator, _Allocator>& __x, |
| 3504 | match_results<_BidirectionalIterator, _Allocator>& __y); |
| 3505 | |
| 3506 | // regex_search |
| 3507 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3508 | template <class _CharT, class _Traits> |
| 3509 | template <class _BidirectionalIterator, class _Allocator> |
| 3510 | bool |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3511 | basic_regex<_CharT, _Traits>::__match_at_start_ecma( |
| 3512 | _BidirectionalIterator __first, _BidirectionalIterator __last, |
| 3513 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 3514 | regex_constants::match_flag_type __flags) const |
| 3515 | { |
| 3516 | return false; |
| 3517 | } |
| 3518 | |
| 3519 | template <class _CharT, class _Traits> |
| 3520 | template <class _BidirectionalIterator, class _Allocator> |
| 3521 | bool |
| 3522 | basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs( |
| 3523 | const _CharT* __first, const _CharT* __last, |
| 3524 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 3525 | vector<size_t>& __lc, |
| 3526 | regex_constants::match_flag_type __flags) const |
| 3527 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3528 | typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; |
| 3529 | __split_buffer<__command> __commands; |
| 3530 | difference_type __j = 0; |
| 3531 | difference_type __highest_j = 0; |
| 3532 | difference_type _N = _STD::distance(__first, __last); |
| 3533 | __state* __st = __start_.get(); |
| 3534 | if (__st) |
| 3535 | { |
| 3536 | __commands.push_front(__command(__st)); |
| 3537 | __commands.push_front(__command(__command::__consume_input)); |
| 3538 | _BidirectionalIterator __current = __first; |
| 3539 | do |
| 3540 | { |
| 3541 | __command __cmd = __commands.back(); |
| 3542 | __commands.pop_back(); |
| 3543 | if (__cmd.first != nullptr) |
| 3544 | __cmd = __cmd.first->__test(__first, __current, __last, __lc, |
| 3545 | __m.__matches_.data(), __flags); |
| 3546 | switch (__cmd.__do_) |
| 3547 | { |
| 3548 | case __command::__end_state: |
| 3549 | __highest_j = _STD::max(__highest_j, __j); |
| 3550 | break; |
| 3551 | case __command::__consume_input: |
| 3552 | if (__j == _N) |
| 3553 | return false; |
| 3554 | ++__current; |
| 3555 | if (++__j != _N && !__commands.empty()) |
| 3556 | __commands.push_front(__command(__command::__consume_input)); |
| 3557 | break; |
| 3558 | case __command::__accept_and_consume: |
| 3559 | __commands.push_front(__command(__cmd.first)); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3560 | break; |
| 3561 | case __command::__accept_but_not_consume: |
| 3562 | __commands.push_back(__command(__cmd.first)); |
| 3563 | if (__cmd.second != nullptr) |
| 3564 | __commands.push_back(__command(__cmd.second)); |
| 3565 | break; |
| 3566 | case __command::__reject: |
| 3567 | break; |
| 3568 | default: |
| 3569 | throw regex_error(regex_constants::error_temp); |
| 3570 | break; |
| 3571 | } |
| 3572 | } while (!__commands.empty()); |
| 3573 | if (__highest_j != 0) |
| 3574 | { |
| 3575 | __m.__matches_[0].first = __first; |
| 3576 | __m.__matches_[0].second = _STD::next(__first, __highest_j); |
| 3577 | __m.__matches_[0].matched = true; |
| 3578 | return true; |
| 3579 | } |
| 3580 | } |
| 3581 | return false; |
| 3582 | } |
| 3583 | |
| 3584 | template <class _CharT, class _Traits> |
| 3585 | template <class _BidirectionalIterator, class _Allocator> |
| 3586 | bool |
| 3587 | basic_regex<_CharT, _Traits>::__match_at_start_posix_subs( |
| 3588 | _BidirectionalIterator __first, _BidirectionalIterator __last, |
| 3589 | match_results<_BidirectionalIterator, _Allocator>& __m, |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame^] | 3590 | vector<size_t>& __lc, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3591 | regex_constants::match_flag_type __flags) const |
| 3592 | { |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame^] | 3593 | typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; |
| 3594 | vector<__command> __commands; |
| 3595 | vector<_BidirectionalIterator> __current_stack; |
| 3596 | vector<sub_match<_BidirectionalIterator> > __saved_matches; |
| 3597 | vector<sub_match<_BidirectionalIterator> > __best_matches; |
| 3598 | difference_type __j = 0; |
| 3599 | difference_type __highest_j = 0; |
| 3600 | difference_type _N = _STD::distance(__first, __last); |
| 3601 | __state* __st = __start_.get(); |
| 3602 | if (__st) |
| 3603 | { |
| 3604 | __commands.push_back(__command(__st)); |
| 3605 | _BidirectionalIterator __current = __first; |
| 3606 | do |
| 3607 | { |
| 3608 | __command __cmd = __commands.back(); |
| 3609 | __commands.pop_back(); |
| 3610 | if (__cmd.first != nullptr) |
| 3611 | __cmd = __cmd.first->__test(__first, __current, __last, __lc, |
| 3612 | __m.__matches_.data(), __flags); |
| 3613 | switch (__cmd.__do_) |
| 3614 | { |
| 3615 | case __command::__end_state: |
| 3616 | if (__highest_j < __j) |
| 3617 | { |
| 3618 | __highest_j = __j; |
| 3619 | for (unsigned __i = 1; __i < __m.__matches_.size(); ++__i) |
| 3620 | __best_matches.push_back(__m.__matches_[__i]); |
| 3621 | } |
| 3622 | break; |
| 3623 | case __command::__pop_state: |
| 3624 | for (unsigned __i = __m.__matches_.size(); __i > 1;) |
| 3625 | { |
| 3626 | assert(!__saved_matches.empty()); |
| 3627 | __m.__matches_[--__i] = __saved_matches.back(); |
| 3628 | __saved_matches.pop_back(); |
| 3629 | } |
| 3630 | assert(!__current_stack.empty()); |
| 3631 | __current = __current_stack.back(); |
| 3632 | __current_stack.pop_back(); |
| 3633 | break; |
| 3634 | case __command::__accept_and_consume: |
| 3635 | __commands.push_back(__command(__cmd.first)); |
| 3636 | if (__current != __last) |
| 3637 | { |
| 3638 | ++__current; |
| 3639 | ++__j; |
| 3640 | } |
| 3641 | break; |
| 3642 | case __command::__accept_but_not_consume: |
| 3643 | if (__cmd.second != nullptr) |
| 3644 | { |
| 3645 | __commands.push_back(__command(__cmd.second)); |
| 3646 | __commands.push_back(__command(__command::__pop_state)); |
| 3647 | __current_stack.push_back(__current); |
| 3648 | for (unsigned __i = 1; __i < __m.__matches_.size(); ++__i) |
| 3649 | __saved_matches.push_back(__m.__matches_[__i]); |
| 3650 | } |
| 3651 | __commands.push_back(__command(__cmd.first)); |
| 3652 | break; |
| 3653 | case __command::__reject: |
| 3654 | break; |
| 3655 | default: |
| 3656 | throw regex_error(regex_constants::error_temp); |
| 3657 | break; |
| 3658 | } |
| 3659 | } while (!__commands.empty()); |
| 3660 | if (__highest_j != 0) |
| 3661 | { |
| 3662 | __m.__matches_[0].first = __first; |
| 3663 | __m.__matches_[0].second = _STD::next(__first, __highest_j); |
| 3664 | __m.__matches_[0].matched = true; |
| 3665 | for (unsigned __i = __m.__matches_.size(); __i > 1;) |
| 3666 | { |
| 3667 | assert(!__best_matches.empty()); |
| 3668 | __m.__matches_[--__i] = __best_matches.back(); |
| 3669 | __best_matches.pop_back(); |
| 3670 | } |
| 3671 | return true; |
| 3672 | } |
| 3673 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3674 | return false; |
| 3675 | } |
| 3676 | |
| 3677 | template <class _CharT, class _Traits> |
| 3678 | template <class _BidirectionalIterator, class _Allocator> |
| 3679 | bool |
| 3680 | basic_regex<_CharT, _Traits>::__match_at_start( |
| 3681 | _BidirectionalIterator __first, _BidirectionalIterator __last, |
| 3682 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 3683 | vector<size_t>& __lc, |
| 3684 | regex_constants::match_flag_type __flags) const |
| 3685 | { |
| 3686 | if (__flags_ & ECMAScript) |
| 3687 | return __match_at_start_ecma(__first, __last, __m, __flags); |
| 3688 | if (mark_count() == 0) |
| 3689 | return __match_at_start_posix_nosubs(__first, __last, __m, __lc, __flags); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame^] | 3690 | return __match_at_start_posix_subs(__first, __last, __m, __lc, __flags); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3691 | } |
| 3692 | |
| 3693 | template <class _CharT, class _Traits> |
| 3694 | template <class _BidirectionalIterator, class _Allocator> |
| 3695 | bool |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3696 | basic_regex<_CharT, _Traits>::__search( |
| 3697 | _BidirectionalIterator __first, _BidirectionalIterator __last, |
| 3698 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 3699 | regex_constants::match_flag_type __flags) const |
| 3700 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3701 | __m.__init(1 + mark_count(), __first, __last); |
| 3702 | vector<size_t> __lc(__loop_count()); |
| 3703 | if (__match_at_start(__first, __last, __m, __lc, __flags)) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3704 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3705 | __m.__prefix_.second = __m[0].first; |
| 3706 | __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; |
| 3707 | __m.__suffix_.first = __m[0].second; |
| 3708 | __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; |
| 3709 | return true; |
| 3710 | } |
| 3711 | if (!(__flags & regex_constants::match_continuous)) |
| 3712 | { |
| 3713 | __m.__matches_.assign(__m.size(), __m.__unmatched_); |
| 3714 | for (++__first; __first != __last; ++__first) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3715 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3716 | if (__match_at_start(__first, __last, __m, __lc, __flags)) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3717 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3718 | __m.__prefix_.second = __m[0].first; |
| 3719 | __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; |
| 3720 | __m.__suffix_.first = __m[0].second; |
| 3721 | __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; |
| 3722 | return true; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3723 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3724 | __m.__matches_.assign(__m.size(), __m.__unmatched_); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3725 | } |
| 3726 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3727 | __m.__matches_.clear(); |
| 3728 | return false; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3729 | } |
| 3730 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 3731 | template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3732 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 3733 | bool |
| 3734 | regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 3735 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 3736 | const basic_regex<_CharT, _Traits>& __e, |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3737 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 3738 | { |
| 3739 | return __e.__search(__first, __last, __m, __flags); |
| 3740 | } |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 3741 | |
| 3742 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 3743 | inline _LIBCPP_INLINE_VISIBILITY |
| 3744 | bool |
| 3745 | regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 3746 | const basic_regex<_CharT, _Traits>& __e, |
| 3747 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 3748 | { |
| 3749 | match_results<_BidirectionalIterator> __m; |
| 3750 | return _STD::regex_search(__first, __last, __m, __e, __flags); |
| 3751 | } |
| 3752 | |
| 3753 | template <class _CharT, class _Allocator, class _Traits> |
| 3754 | inline _LIBCPP_INLINE_VISIBILITY |
| 3755 | bool |
| 3756 | regex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, |
| 3757 | const basic_regex<_CharT, _Traits>& __e, |
| 3758 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 3759 | { |
| 3760 | return _STD::regex_search(__str, __str + _Traits::length(__str), __m, __e, __flags); |
| 3761 | } |
| 3762 | |
| 3763 | template <class _CharT, class _Traits> |
| 3764 | inline _LIBCPP_INLINE_VISIBILITY |
| 3765 | bool |
| 3766 | regex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, |
| 3767 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 3768 | { |
| 3769 | return _STD::regex_search(__str, __str + _Traits::length(__str), __e, __flags); |
| 3770 | } |
| 3771 | |
| 3772 | template <class _ST, class _SA, class _CharT, class _Traits> |
| 3773 | inline _LIBCPP_INLINE_VISIBILITY |
| 3774 | bool |
| 3775 | regex_search(const basic_string<_CharT, _ST, _SA>& __s, |
| 3776 | const basic_regex<_CharT, _Traits>& __e, |
| 3777 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 3778 | { |
| 3779 | return _STD::regex_search(__s.begin(), __s.end(), __e, __flags); |
| 3780 | } |
| 3781 | |
| 3782 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 3783 | inline _LIBCPP_INLINE_VISIBILITY |
| 3784 | bool |
| 3785 | regex_search(const basic_string<_CharT, _ST, _SA>& __s, |
| 3786 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 3787 | const basic_regex<_CharT, _Traits>& __e, |
| 3788 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 3789 | { |
| 3790 | return _STD::regex_search(__s.begin(), __s.end(), __m, __e, __flags); |
| 3791 | } |
| 3792 | |
| 3793 | // regex_match |
| 3794 | |
| 3795 | template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> |
| 3796 | bool |
| 3797 | regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 3798 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 3799 | const basic_regex<_CharT, _Traits>& __e, |
| 3800 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 3801 | { |
| 3802 | bool __r = _STD::regex_search(__first, __last, __m, __e, |
| 3803 | __flags | regex_constants::match_continuous); |
| 3804 | if (__r) |
| 3805 | { |
| 3806 | __r = !__m.suffix().matched; |
| 3807 | if (!__r) |
| 3808 | __m.__matches_.clear(); |
| 3809 | } |
| 3810 | return __r; |
| 3811 | } |
| 3812 | |
| 3813 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 3814 | inline _LIBCPP_INLINE_VISIBILITY |
| 3815 | bool |
| 3816 | regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 3817 | const basic_regex<_CharT, _Traits>& __e, |
| 3818 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 3819 | { |
| 3820 | match_results<_BidirectionalIterator> __m; |
| 3821 | return _STD::regex_match(__first, __last, __m, __e, __flags); |
| 3822 | } |
| 3823 | |
| 3824 | template <class _CharT, class _Allocator, class _Traits> |
| 3825 | inline _LIBCPP_INLINE_VISIBILITY |
| 3826 | bool |
| 3827 | regex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, |
| 3828 | const basic_regex<_CharT, _Traits>& __e, |
| 3829 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 3830 | { |
| 3831 | return _STD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags); |
| 3832 | } |
| 3833 | |
| 3834 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 3835 | inline _LIBCPP_INLINE_VISIBILITY |
| 3836 | bool |
| 3837 | regex_match(const basic_string<_CharT, _ST, _SA>& __s, |
| 3838 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 3839 | const basic_regex<_CharT, _Traits>& __e, |
| 3840 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 3841 | { |
| 3842 | return _STD::regex_match(__s.begin(), __s.end(), __m, __e, __flags); |
| 3843 | } |
| 3844 | |
| 3845 | template <class _CharT, class _Traits> |
| 3846 | inline _LIBCPP_INLINE_VISIBILITY |
| 3847 | bool |
| 3848 | regex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, |
| 3849 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 3850 | { |
| 3851 | return _STD::regex_match(__str, __str + _Traits::length(__str), __e, __flags); |
| 3852 | } |
| 3853 | |
| 3854 | template <class _ST, class _SA, class _CharT, class _Traits> |
| 3855 | inline _LIBCPP_INLINE_VISIBILITY |
| 3856 | bool |
| 3857 | regex_match(const basic_string<_CharT, _ST, _SA>& __s, |
| 3858 | const basic_regex<_CharT, _Traits>& __e, |
| 3859 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 3860 | { |
| 3861 | return _STD::regex_match(__s.begin(), __s.end(), __e, __flags); |
| 3862 | } |
| 3863 | |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 3864 | _LIBCPP_END_NAMESPACE_STD |
| 3865 | |
| 3866 | #endif // _LIBCPP_REGEX |