Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===--------------------------- regex ------------------------------------===// |
| 3 | // |
| 4 | // The LLVM Compiler Infrastructure |
| 5 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 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&); |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 150 | basic_regex(basic_regex&&) noexcept; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 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&); |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 162 | basic_regex& operator=(basic_regex&&) noexcept; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 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); |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 170 | basic_regex& assign(basic_regex&& that) noexcept; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 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 | |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 211 | constexpr sub_match(); |
| 212 | |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 213 | difference_type length() const; |
| 214 | operator string_type() const; |
| 215 | string_type str() const; |
| 216 | |
| 217 | int compare(const sub_match& s) const; |
| 218 | int compare(const string_type& s) const; |
| 219 | int compare(const value_type* s) const; |
| 220 | }; |
| 221 | |
| 222 | typedef sub_match<const char*> csub_match; |
| 223 | typedef sub_match<const wchar_t*> wcsub_match; |
| 224 | typedef sub_match<string::const_iterator> ssub_match; |
| 225 | typedef sub_match<wstring::const_iterator> wssub_match; |
| 226 | |
| 227 | template <class BiIter> |
| 228 | bool |
| 229 | operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); |
| 230 | |
| 231 | template <class BiIter> |
| 232 | bool |
| 233 | operator!=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); |
| 234 | |
| 235 | template <class BiIter> |
| 236 | bool |
| 237 | operator<(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); |
| 238 | |
| 239 | template <class BiIter> |
| 240 | bool |
| 241 | operator<=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); |
| 242 | |
| 243 | template <class BiIter> |
| 244 | bool |
| 245 | operator>=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); |
| 246 | |
| 247 | template <class BiIter> |
| 248 | bool |
| 249 | operator>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); |
| 250 | |
| 251 | template <class BiIter, class ST, class SA> |
| 252 | bool |
| 253 | operator==(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 254 | const sub_match<BiIter>& rhs); |
| 255 | |
| 256 | template <class BiIter, class ST, class SA> |
| 257 | bool |
| 258 | operator!=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 259 | const sub_match<BiIter>& rhs); |
| 260 | |
| 261 | template <class BiIter, class ST, class SA> |
| 262 | bool |
| 263 | operator<(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 264 | const sub_match<BiIter>& rhs); |
| 265 | |
| 266 | template <class BiIter, class ST, class SA> |
| 267 | bool |
| 268 | operator>(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 269 | const sub_match<BiIter>& rhs); |
| 270 | |
| 271 | template <class BiIter, class ST, class SA> |
| 272 | bool operator>=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 273 | const sub_match<BiIter>& rhs); |
| 274 | |
| 275 | template <class BiIter, class ST, class SA> |
| 276 | bool |
| 277 | operator<=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 278 | const sub_match<BiIter>& rhs); |
| 279 | |
| 280 | template <class BiIter, class ST, class SA> |
| 281 | bool |
| 282 | operator==(const sub_match<BiIter>& lhs, |
| 283 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 284 | |
| 285 | template <class BiIter, class ST, class SA> |
| 286 | bool |
| 287 | operator!=(const sub_match<BiIter>& lhs, |
| 288 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 289 | |
| 290 | template <class BiIter, class ST, class SA> |
| 291 | bool |
| 292 | operator<(const sub_match<BiIter>& lhs, |
| 293 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 294 | |
| 295 | template <class BiIter, class ST, class SA> |
| 296 | bool operator>(const sub_match<BiIter>& lhs, |
| 297 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 298 | |
| 299 | template <class BiIter, class ST, class SA> |
| 300 | bool |
| 301 | operator>=(const sub_match<BiIter>& lhs, |
| 302 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 303 | |
| 304 | template <class BiIter, class ST, class SA> |
| 305 | bool |
| 306 | operator<=(const sub_match<BiIter>& lhs, |
| 307 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 308 | |
| 309 | template <class BiIter> |
| 310 | bool |
| 311 | operator==(typename iterator_traits<BiIter>::value_type const* lhs, |
| 312 | const sub_match<BiIter>& rhs); |
| 313 | |
| 314 | template <class BiIter> |
| 315 | bool |
| 316 | operator!=(typename iterator_traits<BiIter>::value_type const* lhs, |
| 317 | const sub_match<BiIter>& rhs); |
| 318 | |
| 319 | template <class BiIter> |
| 320 | bool |
| 321 | operator<(typename iterator_traits<BiIter>::value_type const* lhs, |
| 322 | const sub_match<BiIter>& rhs); |
| 323 | |
| 324 | template <class BiIter> |
| 325 | bool |
| 326 | operator>(typename iterator_traits<BiIter>::value_type const* lhs, |
| 327 | const sub_match<BiIter>& rhs); |
| 328 | |
| 329 | template <class BiIter> |
| 330 | bool |
| 331 | operator>=(typename iterator_traits<BiIter>::value_type const* lhs, |
| 332 | const sub_match<BiIter>& rhs); |
| 333 | |
| 334 | template <class BiIter> |
| 335 | bool |
| 336 | operator<=(typename iterator_traits<BiIter>::value_type const* lhs, |
| 337 | const sub_match<BiIter>& rhs); |
| 338 | |
| 339 | template <class BiIter> |
| 340 | bool |
| 341 | operator==(const sub_match<BiIter>& lhs, |
| 342 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 343 | |
| 344 | template <class BiIter> |
| 345 | bool |
| 346 | operator!=(const sub_match<BiIter>& lhs, |
| 347 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 348 | |
| 349 | template <class BiIter> |
| 350 | bool |
| 351 | operator<(const sub_match<BiIter>& lhs, |
| 352 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 353 | |
| 354 | template <class BiIter> |
| 355 | bool |
| 356 | operator>(const sub_match<BiIter>& lhs, |
| 357 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 358 | |
| 359 | template <class BiIter> |
| 360 | bool |
| 361 | operator>=(const sub_match<BiIter>& lhs, |
| 362 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 363 | |
| 364 | template <class BiIter> |
| 365 | bool |
| 366 | operator<=(const sub_match<BiIter>& lhs, |
| 367 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 368 | |
| 369 | template <class BiIter> |
| 370 | bool |
| 371 | operator==(typename iterator_traits<BiIter>::value_type const& lhs, |
| 372 | const sub_match<BiIter>& rhs); |
| 373 | |
| 374 | template <class BiIter> |
| 375 | bool |
| 376 | operator!=(typename iterator_traits<BiIter>::value_type const& lhs, |
| 377 | const sub_match<BiIter>& rhs); |
| 378 | |
| 379 | template <class BiIter> |
| 380 | bool |
| 381 | operator<(typename iterator_traits<BiIter>::value_type const& lhs, |
| 382 | const sub_match<BiIter>& rhs); |
| 383 | |
| 384 | template <class BiIter> |
| 385 | bool |
| 386 | operator>(typename iterator_traits<BiIter>::value_type const& lhs, |
| 387 | const sub_match<BiIter>& rhs); |
| 388 | |
| 389 | template <class BiIter> |
| 390 | bool |
| 391 | operator>=(typename iterator_traits<BiIter>::value_type const& lhs, |
| 392 | const sub_match<BiIter>& rhs); |
| 393 | |
| 394 | template <class BiIter> |
| 395 | bool |
| 396 | operator<=(typename iterator_traits<BiIter>::value_type const& lhs, |
| 397 | const sub_match<BiIter>& rhs); |
| 398 | |
| 399 | template <class BiIter> |
| 400 | bool |
| 401 | operator==(const sub_match<BiIter>& lhs, |
| 402 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 403 | |
| 404 | template <class BiIter> |
| 405 | bool |
| 406 | operator!=(const sub_match<BiIter>& lhs, |
| 407 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 408 | |
| 409 | template <class BiIter> |
| 410 | bool |
| 411 | operator<(const sub_match<BiIter>& lhs, |
| 412 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 413 | |
| 414 | template <class BiIter> |
| 415 | bool |
| 416 | operator>(const sub_match<BiIter>& lhs, |
| 417 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 418 | |
| 419 | template <class BiIter> |
| 420 | bool |
| 421 | operator>=(const sub_match<BiIter>& lhs, |
| 422 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 423 | |
| 424 | template <class BiIter> |
| 425 | bool |
| 426 | operator<=(const sub_match<BiIter>& lhs, |
| 427 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 428 | |
| 429 | template <class charT, class ST, class BiIter> |
| 430 | basic_ostream<charT, ST>& |
| 431 | operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m); |
| 432 | |
| 433 | template <class BidirectionalIterator, |
| 434 | class Allocator = allocator<sub_match<BidirectionalIterator>>> |
| 435 | class match_results |
| 436 | { |
| 437 | public: |
| 438 | typedef sub_match<BidirectionalIterator> value_type; |
| 439 | typedef const value_type& const_reference; |
| 440 | typedef const_reference reference; |
| 441 | typedef /implementation-defined/ const_iterator; |
| 442 | typedef const_iterator iterator; |
| 443 | typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type; |
| 444 | typedef typename allocator_traits<Allocator>::size_type size_type; |
| 445 | typedef Allocator allocator_type; |
| 446 | typedef typename iterator_traits<BidirectionalIterator>::value_type char_type; |
| 447 | typedef basic_string<char_type> string_type; |
| 448 | |
| 449 | // construct/copy/destroy: |
| 450 | explicit match_results(const Allocator& a = Allocator()); |
| 451 | match_results(const match_results& m); |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 452 | match_results(match_results&& m) noexcept; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 453 | match_results& operator=(const match_results& m); |
| 454 | match_results& operator=(match_results&& m); |
| 455 | ~match_results(); |
| 456 | |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 457 | bool ready() const; |
| 458 | |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 459 | // size: |
| 460 | size_type size() const; |
| 461 | size_type max_size() const; |
| 462 | bool empty() const; |
| 463 | |
| 464 | // element access: |
| 465 | difference_type length(size_type sub = 0) const; |
| 466 | difference_type position(size_type sub = 0) const; |
| 467 | string_type str(size_type sub = 0) const; |
| 468 | const_reference operator[](size_type n) const; |
| 469 | |
| 470 | const_reference prefix() const; |
| 471 | const_reference suffix() const; |
| 472 | |
| 473 | const_iterator begin() const; |
| 474 | const_iterator end() const; |
| 475 | const_iterator cbegin() const; |
| 476 | const_iterator cend() const; |
| 477 | |
| 478 | // format: |
| 479 | template <class OutputIter> |
| 480 | OutputIter |
| 481 | format(OutputIter out, const char_type* fmt_first, |
| 482 | const char_type* fmt_last, |
| 483 | regex_constants::match_flag_type flags = regex_constants::format_default) const; |
| 484 | template <class OutputIter, class ST, class SA> |
| 485 | OutputIter |
| 486 | format(OutputIter out, const basic_string<char_type, ST, SA>& fmt, |
| 487 | regex_constants::match_flag_type flags = regex_constants::format_default) const; |
| 488 | template <class ST, class SA> |
| 489 | basic_string<char_type, ST, SA> |
| 490 | format(const basic_string<char_type, ST, SA>& fmt, |
| 491 | regex_constants::match_flag_type flags = regex_constants::format_default) const; |
| 492 | string_type |
| 493 | format(const char_type* fmt, |
| 494 | regex_constants::match_flag_type flags = regex_constants::format_default) const; |
| 495 | |
| 496 | // allocator: |
| 497 | allocator_type get_allocator() const; |
| 498 | |
| 499 | // swap: |
| 500 | void swap(match_results& that); |
| 501 | }; |
| 502 | |
| 503 | typedef match_results<const char*> cmatch; |
| 504 | typedef match_results<const wchar_t*> wcmatch; |
| 505 | typedef match_results<string::const_iterator> smatch; |
| 506 | typedef match_results<wstring::const_iterator> wsmatch; |
| 507 | |
| 508 | template <class BidirectionalIterator, class Allocator> |
| 509 | bool |
| 510 | operator==(const match_results<BidirectionalIterator, Allocator>& m1, |
| 511 | const match_results<BidirectionalIterator, Allocator>& m2); |
| 512 | |
| 513 | template <class BidirectionalIterator, class Allocator> |
| 514 | bool |
| 515 | operator!=(const match_results<BidirectionalIterator, Allocator>& m1, |
| 516 | const match_results<BidirectionalIterator, Allocator>& m2); |
| 517 | |
| 518 | template <class BidirectionalIterator, class Allocator> |
| 519 | void |
| 520 | swap(match_results<BidirectionalIterator, Allocator>& m1, |
| 521 | match_results<BidirectionalIterator, Allocator>& m2); |
| 522 | |
| 523 | template <class BidirectionalIterator, class Allocator, class charT, class traits> |
| 524 | bool |
| 525 | regex_match(BidirectionalIterator first, BidirectionalIterator last, |
| 526 | match_results<BidirectionalIterator, Allocator>& m, |
| 527 | const basic_regex<charT, traits>& e, |
| 528 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 529 | |
| 530 | template <class BidirectionalIterator, class charT, class traits> |
| 531 | bool |
| 532 | regex_match(BidirectionalIterator first, BidirectionalIterator last, |
| 533 | const basic_regex<charT, traits>& e, |
| 534 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 535 | |
| 536 | template <class charT, class Allocator, class traits> |
| 537 | bool |
| 538 | regex_match(const charT* str, match_results<const charT*, Allocator>& m, |
| 539 | const basic_regex<charT, traits>& e, |
| 540 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 541 | |
| 542 | template <class ST, class SA, class Allocator, class charT, class traits> |
| 543 | bool |
| 544 | regex_match(const basic_string<charT, ST, SA>& s, |
| 545 | match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m, |
| 546 | const basic_regex<charT, traits>& e, |
| 547 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 548 | |
| 549 | template <class charT, class traits> |
| 550 | bool |
| 551 | regex_match(const charT* str, const basic_regex<charT, traits>& e, |
| 552 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 553 | |
| 554 | template <class ST, class SA, class charT, class traits> |
| 555 | bool |
| 556 | regex_match(const basic_string<charT, ST, SA>& s, |
| 557 | const basic_regex<charT, traits>& e, |
| 558 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 559 | |
| 560 | template <class BidirectionalIterator, class Allocator, class charT, class traits> |
| 561 | bool |
| 562 | regex_search(BidirectionalIterator first, BidirectionalIterator last, |
| 563 | match_results<BidirectionalIterator, Allocator>& m, |
| 564 | const basic_regex<charT, traits>& e, |
| 565 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 566 | |
| 567 | template <class BidirectionalIterator, class charT, class traits> |
| 568 | bool |
| 569 | regex_search(BidirectionalIterator first, BidirectionalIterator last, |
| 570 | const basic_regex<charT, traits>& e, |
| 571 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 572 | |
| 573 | template <class charT, class Allocator, class traits> |
| 574 | bool |
| 575 | regex_search(const charT* str, match_results<const charT*, Allocator>& m, |
| 576 | const basic_regex<charT, traits>& e, |
| 577 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 578 | |
| 579 | template <class charT, class traits> |
| 580 | bool |
| 581 | regex_search(const charT* str, const basic_regex<charT, traits>& e, |
| 582 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 583 | |
| 584 | template <class ST, class SA, class charT, class traits> |
| 585 | bool |
| 586 | regex_search(const basic_string<charT, ST, SA>& s, |
| 587 | const basic_regex<charT, traits>& e, |
| 588 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 589 | |
| 590 | template <class ST, class SA, class Allocator, class charT, class traits> |
| 591 | bool |
| 592 | regex_search(const basic_string<charT, ST, SA>& s, |
| 593 | match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m, |
| 594 | const basic_regex<charT, traits>& e, |
| 595 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 596 | |
| 597 | template <class OutputIterator, class BidirectionalIterator, |
| 598 | class traits, class charT, class ST, class SA> |
| 599 | OutputIterator |
| 600 | regex_replace(OutputIterator out, |
| 601 | BidirectionalIterator first, BidirectionalIterator last, |
| 602 | const basic_regex<charT, traits>& e, |
| 603 | const basic_string<charT, ST, SA>& fmt, |
| 604 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 605 | |
| 606 | template <class OutputIterator, class BidirectionalIterator, |
| 607 | class traits, class charT> |
| 608 | OutputIterator |
| 609 | regex_replace(OutputIterator out, |
| 610 | BidirectionalIterator first, BidirectionalIterator last, |
| 611 | const basic_regex<charT, traits>& e, const charT* fmt, |
| 612 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 613 | |
| 614 | template <class traits, class charT, class ST, class SA, class FST, class FSA>> |
| 615 | basic_string<charT, ST, SA> |
| 616 | regex_replace(const basic_string<charT, ST, SA>& s, |
| 617 | const basic_regex<charT, traits>& e, |
| 618 | const basic_string<charT, FST, FSA>& fmt, |
| 619 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 620 | |
| 621 | template <class traits, class charT, class ST, class SA> |
| 622 | basic_string<charT, ST, SA> |
| 623 | regex_replace(const basic_string<charT, ST, SA>& s, |
| 624 | const basic_regex<charT, traits>& e, const charT* fmt, |
| 625 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 626 | |
| 627 | template <class traits, class charT, class ST, class SA> |
| 628 | basic_string<charT> |
| 629 | regex_replace(const charT* s, |
| 630 | const basic_regex<charT, traits>& e, |
| 631 | const basic_string<charT, ST, SA>& fmt, |
| 632 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 633 | |
| 634 | template <class traits, class charT> |
| 635 | basic_string<charT> |
| 636 | regex_replace(const charT* s, |
| 637 | const basic_regex<charT, traits>& e, |
| 638 | const charT* fmt, |
| 639 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 640 | |
| 641 | template <class BidirectionalIterator, |
| 642 | class charT = typename iterator_traits< BidirectionalIterator>::value_type, |
| 643 | class traits = regex_traits<charT>> |
| 644 | class regex_iterator |
| 645 | { |
| 646 | public: |
| 647 | typedef basic_regex<charT, traits> regex_type; |
| 648 | typedef match_results<BidirectionalIterator> value_type; |
| 649 | typedef ptrdiff_t difference_type; |
| 650 | typedef const value_type* pointer; |
| 651 | typedef const value_type& reference; |
| 652 | typedef forward_iterator_tag iterator_category; |
| 653 | |
| 654 | regex_iterator(); |
| 655 | regex_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 656 | const regex_type& re, |
| 657 | regex_constants::match_flag_type m = regex_constants::match_default); |
| 658 | regex_iterator(const regex_iterator&); |
| 659 | regex_iterator& operator=(const regex_iterator&); |
| 660 | |
| 661 | bool operator==(const regex_iterator&) const; |
| 662 | bool operator!=(const regex_iterator&) const; |
| 663 | |
| 664 | const value_type& operator*() const; |
| 665 | const value_type* operator->() const; |
| 666 | |
| 667 | regex_iterator& operator++(); |
| 668 | regex_iterator operator++(int); |
| 669 | }; |
| 670 | |
| 671 | typedef regex_iterator<const char*> cregex_iterator; |
| 672 | typedef regex_iterator<const wchar_t*> wcregex_iterator; |
| 673 | typedef regex_iterator<string::const_iterator> sregex_iterator; |
| 674 | typedef regex_iterator<wstring::const_iterator> wsregex_iterator; |
| 675 | |
| 676 | template <class BidirectionalIterator, |
| 677 | class charT = typename iterator_traits< BidirectionalIterator>::value_type, |
| 678 | class traits = regex_traits<charT>> |
| 679 | class regex_token_iterator |
| 680 | { |
| 681 | public: |
| 682 | typedef basic_regex<charT, traits> regex_type; |
| 683 | typedef sub_match<BidirectionalIterator> value_type; |
| 684 | typedef ptrdiff_t difference_type; |
| 685 | typedef const value_type* pointer; |
| 686 | typedef const value_type& reference; |
| 687 | typedef forward_iterator_tag iterator_category; |
| 688 | |
| 689 | regex_token_iterator(); |
| 690 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 691 | const regex_type& re, int submatch = 0, |
| 692 | regex_constants::match_flag_type m = regex_constants::match_default); |
| 693 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 694 | const regex_type& re, const vector<int>& submatches, |
| 695 | regex_constants::match_flag_type m = regex_constants::match_default); |
| 696 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 697 | const regex_type& re, initializer_list<int> submatches, |
| 698 | regex_constants::match_flag_type m = regex_constants::match_default); |
| 699 | template <size_t N> |
| 700 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 701 | const regex_type& re, const int (&submatches)[N], |
| 702 | regex_constants::match_flag_type m = regex_constants::match_default); |
| 703 | regex_token_iterator(const regex_token_iterator&); |
| 704 | regex_token_iterator& operator=(const regex_token_iterator&); |
| 705 | |
| 706 | bool operator==(const regex_token_iterator&) const; |
| 707 | bool operator!=(const regex_token_iterator&) const; |
| 708 | |
| 709 | const value_type& operator*() const; |
| 710 | const value_type* operator->() const; |
| 711 | |
| 712 | regex_token_iterator& operator++(); |
| 713 | regex_token_iterator operator++(int); |
| 714 | }; |
| 715 | |
| 716 | typedef regex_token_iterator<const char*> cregex_token_iterator; |
| 717 | typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator; |
| 718 | typedef regex_token_iterator<string::const_iterator> sregex_token_iterator; |
| 719 | typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator; |
| 720 | |
| 721 | } // std |
| 722 | */ |
| 723 | |
| 724 | #include <__config> |
| 725 | #include <stdexcept> |
| 726 | #include <__locale> |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 727 | #include <initializer_list> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 728 | #include <utility> |
| 729 | #include <iterator> |
| 730 | #include <string> |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 731 | #include <memory> |
| 732 | #include <vector> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 733 | #include <deque> |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 734 | |
Howard Hinnant | 66c6f97 | 2011-11-29 16:45:27 +0000 | [diff] [blame] | 735 | #include <__undef_min_max> |
| 736 | |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 737 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 738 | #pragma GCC system_header |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 739 | #endif |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 740 | |
| 741 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 742 | |
| 743 | namespace regex_constants |
| 744 | { |
| 745 | |
| 746 | // syntax_option_type |
| 747 | |
| 748 | enum syntax_option_type |
| 749 | { |
| 750 | icase = 1 << 0, |
| 751 | nosubs = 1 << 1, |
| 752 | optimize = 1 << 2, |
| 753 | collate = 1 << 3, |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 754 | ECMAScript = 0, |
| 755 | basic = 1 << 4, |
| 756 | extended = 1 << 5, |
| 757 | awk = 1 << 6, |
| 758 | grep = 1 << 7, |
| 759 | egrep = 1 << 8 |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 760 | }; |
| 761 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 762 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 763 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 764 | syntax_option_type |
| 765 | operator~(syntax_option_type __x) |
| 766 | { |
| 767 | return syntax_option_type(~int(__x)); |
| 768 | } |
| 769 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 770 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 771 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 772 | syntax_option_type |
| 773 | operator&(syntax_option_type __x, syntax_option_type __y) |
| 774 | { |
| 775 | return syntax_option_type(int(__x) & int(__y)); |
| 776 | } |
| 777 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 778 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 779 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 780 | syntax_option_type |
| 781 | operator|(syntax_option_type __x, syntax_option_type __y) |
| 782 | { |
| 783 | return syntax_option_type(int(__x) | int(__y)); |
| 784 | } |
| 785 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 786 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 787 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 788 | syntax_option_type |
| 789 | operator^(syntax_option_type __x, syntax_option_type __y) |
| 790 | { |
| 791 | return syntax_option_type(int(__x) ^ int(__y)); |
| 792 | } |
| 793 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 794 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 795 | syntax_option_type& |
| 796 | operator&=(syntax_option_type& __x, syntax_option_type __y) |
| 797 | { |
| 798 | __x = __x & __y; |
| 799 | return __x; |
| 800 | } |
| 801 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 802 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 803 | syntax_option_type& |
| 804 | operator|=(syntax_option_type& __x, syntax_option_type __y) |
| 805 | { |
| 806 | __x = __x | __y; |
| 807 | return __x; |
| 808 | } |
| 809 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 810 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 811 | syntax_option_type& |
| 812 | operator^=(syntax_option_type& __x, syntax_option_type __y) |
| 813 | { |
| 814 | __x = __x ^ __y; |
| 815 | return __x; |
| 816 | } |
| 817 | |
| 818 | // match_flag_type |
| 819 | |
| 820 | enum match_flag_type |
| 821 | { |
| 822 | match_default = 0, |
| 823 | match_not_bol = 1 << 0, |
| 824 | match_not_eol = 1 << 1, |
| 825 | match_not_bow = 1 << 2, |
| 826 | match_not_eow = 1 << 3, |
| 827 | match_any = 1 << 4, |
| 828 | match_not_null = 1 << 5, |
| 829 | match_continuous = 1 << 6, |
| 830 | match_prev_avail = 1 << 7, |
| 831 | format_default = 0, |
| 832 | format_sed = 1 << 8, |
| 833 | format_no_copy = 1 << 9, |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 834 | format_first_only = 1 << 10, |
| 835 | __no_update_pos = 1 << 11 |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 836 | }; |
| 837 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 838 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 839 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 840 | match_flag_type |
| 841 | operator~(match_flag_type __x) |
| 842 | { |
| 843 | return match_flag_type(~int(__x)); |
| 844 | } |
| 845 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 846 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 847 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 848 | match_flag_type |
| 849 | operator&(match_flag_type __x, match_flag_type __y) |
| 850 | { |
| 851 | return match_flag_type(int(__x) & int(__y)); |
| 852 | } |
| 853 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 854 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 855 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 856 | match_flag_type |
| 857 | operator|(match_flag_type __x, match_flag_type __y) |
| 858 | { |
| 859 | return match_flag_type(int(__x) | int(__y)); |
| 860 | } |
| 861 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 862 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 863 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 864 | match_flag_type |
| 865 | operator^(match_flag_type __x, match_flag_type __y) |
| 866 | { |
| 867 | return match_flag_type(int(__x) ^ int(__y)); |
| 868 | } |
| 869 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 870 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 871 | match_flag_type& |
| 872 | operator&=(match_flag_type& __x, match_flag_type __y) |
| 873 | { |
| 874 | __x = __x & __y; |
| 875 | return __x; |
| 876 | } |
| 877 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 878 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 879 | match_flag_type& |
| 880 | operator|=(match_flag_type& __x, match_flag_type __y) |
| 881 | { |
| 882 | __x = __x | __y; |
| 883 | return __x; |
| 884 | } |
| 885 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 886 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 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, |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 909 | __re_err_grammar, |
| 910 | __re_err_empty, |
| 911 | __re_err_unknown |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 912 | }; |
| 913 | |
| 914 | } // regex_constants |
| 915 | |
| 916 | class _LIBCPP_EXCEPTION_ABI regex_error |
| 917 | : public runtime_error |
| 918 | { |
| 919 | regex_constants::error_type __code_; |
| 920 | public: |
| 921 | explicit regex_error(regex_constants::error_type __ecode); |
| 922 | virtual ~regex_error() throw(); |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 923 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 924 | regex_constants::error_type code() const {return __code_;} |
| 925 | }; |
| 926 | |
| 927 | template <class _CharT> |
Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame^] | 928 | struct _LIBCPP_TYPE_VIS regex_traits |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 929 | { |
| 930 | public: |
| 931 | typedef _CharT char_type; |
| 932 | typedef basic_string<char_type> string_type; |
| 933 | typedef locale locale_type; |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 934 | typedef ctype_base::mask char_class_type; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 935 | |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 936 | static const char_class_type __regex_word = 0x80; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 937 | private: |
| 938 | locale __loc_; |
| 939 | const ctype<char_type>* __ct_; |
| 940 | const collate<char_type>* __col_; |
| 941 | |
| 942 | public: |
| 943 | regex_traits(); |
| 944 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 945 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 946 | static size_t length(const char_type* __p) |
| 947 | {return char_traits<char_type>::length(__p);} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 948 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 949 | char_type translate(char_type __c) const {return __c;} |
| 950 | char_type translate_nocase(char_type __c) const; |
| 951 | template <class _ForwardIterator> |
| 952 | string_type |
| 953 | transform(_ForwardIterator __f, _ForwardIterator __l) const; |
| 954 | template <class _ForwardIterator> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 955 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 956 | string_type |
| 957 | transform_primary( _ForwardIterator __f, _ForwardIterator __l) const |
| 958 | {return __transform_primary(__f, __l, char_type());} |
| 959 | template <class _ForwardIterator> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 960 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 961 | string_type |
| 962 | lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const |
| 963 | {return __lookup_collatename(__f, __l, char_type());} |
| 964 | template <class _ForwardIterator> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 965 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 966 | char_class_type |
| 967 | lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 968 | bool __icase = false) const |
| 969 | {return __lookup_classname(__f, __l, __icase, char_type());} |
| 970 | bool isctype(char_type __c, char_class_type __m) const; |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 971 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 972 | int value(char_type __ch, int __radix) const |
| 973 | {return __value(__ch, __radix);} |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 974 | locale_type imbue(locale_type __l); |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 975 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 976 | locale_type getloc()const {return __loc_;} |
| 977 | |
| 978 | private: |
| 979 | void __init(); |
| 980 | |
| 981 | template <class _ForwardIterator> |
| 982 | string_type |
| 983 | __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const; |
| 984 | template <class _ForwardIterator> |
| 985 | string_type |
| 986 | __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; |
| 987 | |
| 988 | template <class _ForwardIterator> |
| 989 | string_type |
| 990 | __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const; |
| 991 | template <class _ForwardIterator> |
| 992 | string_type |
| 993 | __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 994 | |
| 995 | template <class _ForwardIterator> |
| 996 | char_class_type |
| 997 | __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
| 998 | bool __icase, char) const; |
| 999 | template <class _ForwardIterator> |
| 1000 | char_class_type |
| 1001 | __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
| 1002 | bool __icase, wchar_t) const; |
| 1003 | |
| 1004 | static int __value(unsigned char __ch, int __radix); |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1005 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1006 | int __value(char __ch, int __radix) const |
| 1007 | {return __value(static_cast<unsigned char>(__ch), __radix);} |
| 1008 | int __value(wchar_t __ch, int __radix) const; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1009 | }; |
| 1010 | |
| 1011 | template <class _CharT> |
| 1012 | regex_traits<_CharT>::regex_traits() |
| 1013 | { |
| 1014 | __init(); |
| 1015 | } |
| 1016 | |
| 1017 | template <class _CharT> |
| 1018 | typename regex_traits<_CharT>::char_type |
| 1019 | regex_traits<_CharT>::translate_nocase(char_type __c) const |
| 1020 | { |
| 1021 | return __ct_->tolower(__c); |
| 1022 | } |
| 1023 | |
| 1024 | template <class _CharT> |
| 1025 | template <class _ForwardIterator> |
| 1026 | typename regex_traits<_CharT>::string_type |
| 1027 | regex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const |
| 1028 | { |
| 1029 | string_type __s(__f, __l); |
| 1030 | return __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1031 | } |
| 1032 | |
| 1033 | template <class _CharT> |
| 1034 | void |
| 1035 | regex_traits<_CharT>::__init() |
| 1036 | { |
| 1037 | __ct_ = &use_facet<ctype<char_type> >(__loc_); |
| 1038 | __col_ = &use_facet<collate<char_type> >(__loc_); |
| 1039 | } |
| 1040 | |
| 1041 | template <class _CharT> |
| 1042 | typename regex_traits<_CharT>::locale_type |
| 1043 | regex_traits<_CharT>::imbue(locale_type __l) |
| 1044 | { |
| 1045 | locale __r = __loc_; |
| 1046 | __loc_ = __l; |
| 1047 | __init(); |
| 1048 | return __r; |
| 1049 | } |
| 1050 | |
| 1051 | // transform_primary is very FreeBSD-specific |
| 1052 | |
| 1053 | template <class _CharT> |
| 1054 | template <class _ForwardIterator> |
| 1055 | typename regex_traits<_CharT>::string_type |
| 1056 | regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, |
| 1057 | _ForwardIterator __l, char) const |
| 1058 | { |
| 1059 | const string_type __s(__f, __l); |
| 1060 | string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1061 | switch (__d.size()) |
| 1062 | { |
| 1063 | case 1: |
| 1064 | break; |
| 1065 | case 12: |
| 1066 | __d[11] = __d[3]; |
| 1067 | break; |
| 1068 | default: |
| 1069 | __d.clear(); |
| 1070 | break; |
| 1071 | } |
| 1072 | return __d; |
| 1073 | } |
| 1074 | |
| 1075 | template <class _CharT> |
| 1076 | template <class _ForwardIterator> |
| 1077 | typename regex_traits<_CharT>::string_type |
| 1078 | regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, |
| 1079 | _ForwardIterator __l, wchar_t) const |
| 1080 | { |
| 1081 | const string_type __s(__f, __l); |
| 1082 | string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1083 | switch (__d.size()) |
| 1084 | { |
| 1085 | case 1: |
| 1086 | break; |
| 1087 | case 3: |
| 1088 | __d[2] = __d[0]; |
| 1089 | break; |
| 1090 | default: |
| 1091 | __d.clear(); |
| 1092 | break; |
| 1093 | } |
| 1094 | return __d; |
| 1095 | } |
| 1096 | |
| 1097 | // lookup_collatename is very FreeBSD-specific |
| 1098 | |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1099 | string __get_collation_name(const char* __s); |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1100 | |
| 1101 | template <class _CharT> |
| 1102 | template <class _ForwardIterator> |
| 1103 | typename regex_traits<_CharT>::string_type |
| 1104 | regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, |
| 1105 | _ForwardIterator __l, char) const |
| 1106 | { |
| 1107 | string_type __s(__f, __l); |
| 1108 | string_type __r; |
| 1109 | if (!__s.empty()) |
| 1110 | { |
| 1111 | __r = __get_collation_name(__s.c_str()); |
| 1112 | if (__r.empty() && __s.size() <= 2) |
| 1113 | { |
| 1114 | __r = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1115 | if (__r.size() == 1 || __r.size() == 12) |
| 1116 | __r = __s; |
| 1117 | else |
| 1118 | __r.clear(); |
| 1119 | } |
| 1120 | } |
| 1121 | return __r; |
| 1122 | } |
| 1123 | |
| 1124 | template <class _CharT> |
| 1125 | template <class _ForwardIterator> |
| 1126 | typename regex_traits<_CharT>::string_type |
| 1127 | regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, |
| 1128 | _ForwardIterator __l, wchar_t) const |
| 1129 | { |
| 1130 | string_type __s(__f, __l); |
| 1131 | string __n; |
| 1132 | __n.reserve(__s.size()); |
| 1133 | for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); |
| 1134 | __i != __e; ++__i) |
| 1135 | { |
| 1136 | if (static_cast<unsigned>(*__i) >= 127) |
| 1137 | return string_type(); |
| 1138 | __n.push_back(char(*__i)); |
| 1139 | } |
| 1140 | string_type __r; |
| 1141 | if (!__s.empty()) |
| 1142 | { |
| 1143 | __n = __get_collation_name(__n.c_str()); |
| 1144 | if (!__n.empty()) |
| 1145 | __r.assign(__n.begin(), __n.end()); |
| 1146 | else if (__s.size() <= 2) |
| 1147 | { |
| 1148 | __r = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1149 | if (__r.size() == 1 || __r.size() == 3) |
| 1150 | __r = __s; |
| 1151 | else |
| 1152 | __r.clear(); |
| 1153 | } |
| 1154 | } |
| 1155 | return __r; |
| 1156 | } |
| 1157 | |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1158 | // lookup_classname |
| 1159 | |
| 1160 | ctype_base::mask __get_classname(const char* __s, bool __icase); |
| 1161 | |
| 1162 | template <class _CharT> |
| 1163 | template <class _ForwardIterator> |
| 1164 | typename regex_traits<_CharT>::char_class_type |
| 1165 | regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, |
| 1166 | _ForwardIterator __l, |
| 1167 | bool __icase, char) const |
| 1168 | { |
| 1169 | string_type __s(__f, __l); |
| 1170 | __ct_->tolower(&__s[0], &__s[0] + __s.size()); |
| 1171 | return __get_classname(__s.c_str(), __icase); |
| 1172 | } |
| 1173 | |
| 1174 | template <class _CharT> |
| 1175 | template <class _ForwardIterator> |
| 1176 | typename regex_traits<_CharT>::char_class_type |
| 1177 | regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, |
| 1178 | _ForwardIterator __l, |
| 1179 | bool __icase, wchar_t) const |
| 1180 | { |
| 1181 | string_type __s(__f, __l); |
| 1182 | __ct_->tolower(&__s[0], &__s[0] + __s.size()); |
| 1183 | string __n; |
| 1184 | __n.reserve(__s.size()); |
| 1185 | for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); |
| 1186 | __i != __e; ++__i) |
| 1187 | { |
| 1188 | if (static_cast<unsigned>(*__i) >= 127) |
| 1189 | return char_class_type(); |
| 1190 | __n.push_back(char(*__i)); |
| 1191 | } |
| 1192 | return __get_classname(__n.c_str(), __icase); |
| 1193 | } |
| 1194 | |
| 1195 | template <class _CharT> |
| 1196 | bool |
| 1197 | regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const |
| 1198 | { |
| 1199 | if (__ct_->is(__m, __c)) |
| 1200 | return true; |
| 1201 | return (__c == '_' && (__m & __regex_word)); |
| 1202 | } |
| 1203 | |
| 1204 | template <class _CharT> |
| 1205 | int |
| 1206 | regex_traits<_CharT>::__value(unsigned char __ch, int __radix) |
| 1207 | { |
| 1208 | if ((__ch & 0xF8u) == 0x30) // '0' <= __ch && __ch <= '7' |
| 1209 | return __ch - '0'; |
| 1210 | if (__radix != 8) |
| 1211 | { |
| 1212 | if ((__ch & 0xFEu) == 0x38) // '8' <= __ch && __ch <= '9' |
| 1213 | return __ch - '0'; |
| 1214 | if (__radix == 16) |
| 1215 | { |
| 1216 | __ch |= 0x20; // tolower |
| 1217 | if ('a' <= __ch && __ch <= 'f') |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 1218 | return __ch - ('a' - 10); |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1219 | } |
| 1220 | } |
| 1221 | return -1; |
| 1222 | } |
| 1223 | |
| 1224 | template <class _CharT> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1225 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1226 | int |
| 1227 | regex_traits<_CharT>::__value(wchar_t __ch, int __radix) const |
| 1228 | { |
| 1229 | return __value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix); |
| 1230 | } |
| 1231 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1232 | template <class _CharT> class __node; |
| 1233 | |
Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame^] | 1234 | template <class _BidirectionalIterator> class _LIBCPP_TYPE_VIS sub_match; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1235 | |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1236 | template <class _BidirectionalIterator, |
| 1237 | class _Allocator = allocator<sub_match<_BidirectionalIterator> > > |
Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame^] | 1238 | class _LIBCPP_TYPE_VIS match_results; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1239 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1240 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1241 | struct __state |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1242 | { |
| 1243 | enum |
| 1244 | { |
| 1245 | __end_state = -1000, |
| 1246 | __consume_input, // -999 |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1247 | __begin_marked_expr, // -998 |
| 1248 | __end_marked_expr, // -997 |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1249 | __pop_state, // -996 |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1250 | __accept_and_consume, // -995 |
| 1251 | __accept_but_not_consume, // -994 |
| 1252 | __reject, // -993 |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1253 | __split, |
| 1254 | __repeat |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1255 | }; |
| 1256 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1257 | int __do_; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1258 | const _CharT* __first_; |
| 1259 | const _CharT* __current_; |
| 1260 | const _CharT* __last_; |
| 1261 | vector<sub_match<const _CharT*> > __sub_matches_; |
| 1262 | vector<pair<size_t, const _CharT*> > __loop_data_; |
| 1263 | const __node<_CharT>* __node_; |
| 1264 | regex_constants::match_flag_type __flags_; |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 1265 | bool __at_first_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1266 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1267 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1268 | __state() |
| 1269 | : __do_(0), __first_(nullptr), __current_(nullptr), __last_(nullptr), |
| 1270 | __node_(nullptr), __flags_() {} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1271 | }; |
| 1272 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1273 | // __node |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1274 | |
| 1275 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1276 | class __node |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1277 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1278 | __node(const __node&); |
| 1279 | __node& operator=(const __node&); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1280 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1281 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1282 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1283 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1284 | __node() {} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1285 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1286 | virtual ~__node() {} |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1287 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1288 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1289 | virtual void __exec(__state&) const {}; |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1290 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1291 | virtual void __exec_split(bool, __state&) const {}; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1292 | }; |
| 1293 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1294 | // __end_state |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1295 | |
| 1296 | template <class _CharT> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1297 | class __end_state |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1298 | : public __node<_CharT> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1299 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1300 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1301 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1302 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1303 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1304 | __end_state() {} |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1305 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1306 | virtual void __exec(__state&) const; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1307 | }; |
| 1308 | |
| 1309 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1310 | void |
| 1311 | __end_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1312 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1313 | __s.__do_ = __state::__end_state; |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1314 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1315 | |
| 1316 | // __has_one_state |
| 1317 | |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1318 | template <class _CharT> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1319 | class __has_one_state |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1320 | : public __node<_CharT> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1321 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1322 | __node<_CharT>* __first_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1323 | |
| 1324 | public: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1325 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1326 | explicit __has_one_state(__node<_CharT>* __s) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1327 | : __first_(__s) {} |
| 1328 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1329 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1330 | __node<_CharT>* first() const {return __first_;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1331 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1332 | __node<_CharT>*& first() {return __first_;} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1333 | }; |
| 1334 | |
| 1335 | // __owns_one_state |
| 1336 | |
| 1337 | template <class _CharT> |
| 1338 | class __owns_one_state |
| 1339 | : public __has_one_state<_CharT> |
| 1340 | { |
| 1341 | typedef __has_one_state<_CharT> base; |
| 1342 | |
| 1343 | public: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1344 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1345 | explicit __owns_one_state(__node<_CharT>* __s) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1346 | : base(__s) {} |
| 1347 | |
| 1348 | virtual ~__owns_one_state(); |
| 1349 | }; |
| 1350 | |
| 1351 | template <class _CharT> |
| 1352 | __owns_one_state<_CharT>::~__owns_one_state() |
| 1353 | { |
| 1354 | delete this->first(); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1355 | } |
| 1356 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1357 | // __empty_state |
| 1358 | |
| 1359 | template <class _CharT> |
| 1360 | class __empty_state |
| 1361 | : public __owns_one_state<_CharT> |
| 1362 | { |
| 1363 | typedef __owns_one_state<_CharT> base; |
| 1364 | |
| 1365 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1366 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1367 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1368 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1369 | explicit __empty_state(__node<_CharT>* __s) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1370 | : base(__s) {} |
| 1371 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1372 | virtual void __exec(__state&) const; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1373 | }; |
| 1374 | |
| 1375 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1376 | void |
| 1377 | __empty_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1378 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1379 | __s.__do_ = __state::__accept_but_not_consume; |
| 1380 | __s.__node_ = this->first(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1381 | } |
| 1382 | |
| 1383 | // __empty_non_own_state |
| 1384 | |
| 1385 | template <class _CharT> |
| 1386 | class __empty_non_own_state |
| 1387 | : public __has_one_state<_CharT> |
| 1388 | { |
| 1389 | typedef __has_one_state<_CharT> base; |
| 1390 | |
| 1391 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1392 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1393 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1394 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1395 | explicit __empty_non_own_state(__node<_CharT>* __s) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1396 | : base(__s) {} |
| 1397 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1398 | virtual void __exec(__state&) const; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1399 | }; |
| 1400 | |
| 1401 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1402 | void |
| 1403 | __empty_non_own_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1404 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1405 | __s.__do_ = __state::__accept_but_not_consume; |
| 1406 | __s.__node_ = this->first(); |
| 1407 | } |
| 1408 | |
| 1409 | // __repeat_one_loop |
| 1410 | |
| 1411 | template <class _CharT> |
| 1412 | class __repeat_one_loop |
| 1413 | : public __has_one_state<_CharT> |
| 1414 | { |
| 1415 | typedef __has_one_state<_CharT> base; |
| 1416 | |
| 1417 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1418 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1419 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1420 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1421 | explicit __repeat_one_loop(__node<_CharT>* __s) |
| 1422 | : base(__s) {} |
| 1423 | |
| 1424 | virtual void __exec(__state&) const; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1425 | }; |
| 1426 | |
| 1427 | template <class _CharT> |
| 1428 | void |
| 1429 | __repeat_one_loop<_CharT>::__exec(__state& __s) const |
| 1430 | { |
| 1431 | __s.__do_ = __state::__repeat; |
| 1432 | __s.__node_ = this->first(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1433 | } |
| 1434 | |
| 1435 | // __owns_two_states |
| 1436 | |
| 1437 | template <class _CharT> |
| 1438 | class __owns_two_states |
| 1439 | : public __owns_one_state<_CharT> |
| 1440 | { |
| 1441 | typedef __owns_one_state<_CharT> base; |
| 1442 | |
| 1443 | base* __second_; |
| 1444 | |
| 1445 | public: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1446 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1447 | explicit __owns_two_states(__node<_CharT>* __s1, base* __s2) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1448 | : base(__s1), __second_(__s2) {} |
| 1449 | |
| 1450 | virtual ~__owns_two_states(); |
| 1451 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1452 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1453 | base* second() const {return __second_;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1454 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1455 | base*& second() {return __second_;} |
| 1456 | }; |
| 1457 | |
| 1458 | template <class _CharT> |
| 1459 | __owns_two_states<_CharT>::~__owns_two_states() |
| 1460 | { |
| 1461 | delete __second_; |
| 1462 | } |
| 1463 | |
| 1464 | // __loop |
| 1465 | |
| 1466 | template <class _CharT> |
| 1467 | class __loop |
| 1468 | : public __owns_two_states<_CharT> |
| 1469 | { |
| 1470 | typedef __owns_two_states<_CharT> base; |
| 1471 | |
| 1472 | size_t __min_; |
| 1473 | size_t __max_; |
| 1474 | unsigned __loop_id_; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1475 | unsigned __mexp_begin_; |
| 1476 | unsigned __mexp_end_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1477 | bool __greedy_; |
| 1478 | |
| 1479 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1480 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1481 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1482 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1483 | explicit __loop(unsigned __loop_id, |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1484 | __node<_CharT>* __s1, __owns_one_state<_CharT>* __s2, |
| 1485 | unsigned __mexp_begin, unsigned __mexp_end, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1486 | bool __greedy = true, |
| 1487 | size_t __min = 0, |
| 1488 | size_t __max = numeric_limits<size_t>::max()) |
| 1489 | : base(__s1, __s2), __min_(__min), __max_(__max), __loop_id_(__loop_id), |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1490 | __mexp_begin_(__mexp_begin), __mexp_end_(__mexp_end), |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1491 | __greedy_(__greedy) {} |
| 1492 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1493 | virtual void __exec(__state& __s) const; |
| 1494 | virtual void __exec_split(bool __second, __state& __s) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1495 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1496 | private: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1497 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1498 | void __init_repeat(__state& __s) const |
| 1499 | { |
| 1500 | __s.__loop_data_[__loop_id_].second = __s.__current_; |
| 1501 | for (size_t __i = __mexp_begin_-1; __i != __mexp_end_-1; ++__i) |
| 1502 | { |
| 1503 | __s.__sub_matches_[__i].first = __s.__last_; |
| 1504 | __s.__sub_matches_[__i].second = __s.__last_; |
| 1505 | __s.__sub_matches_[__i].matched = false; |
| 1506 | } |
| 1507 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1508 | }; |
| 1509 | |
| 1510 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1511 | void |
| 1512 | __loop<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1513 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1514 | if (__s.__do_ == __state::__repeat) |
| 1515 | { |
| 1516 | bool __do_repeat = ++__s.__loop_data_[__loop_id_].first < __max_; |
| 1517 | bool __do_alt = __s.__loop_data_[__loop_id_].first >= __min_; |
| 1518 | if (__do_repeat && __do_alt && |
| 1519 | __s.__loop_data_[__loop_id_].second == __s.__current_) |
| 1520 | __do_repeat = false; |
| 1521 | if (__do_repeat && __do_alt) |
| 1522 | __s.__do_ = __state::__split; |
| 1523 | else if (__do_repeat) |
| 1524 | { |
| 1525 | __s.__do_ = __state::__accept_but_not_consume; |
| 1526 | __s.__node_ = this->first(); |
| 1527 | __init_repeat(__s); |
| 1528 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1529 | else |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1530 | { |
| 1531 | __s.__do_ = __state::__accept_but_not_consume; |
| 1532 | __s.__node_ = this->second(); |
| 1533 | } |
| 1534 | } |
| 1535 | else |
| 1536 | { |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 1537 | __s.__loop_data_[__loop_id_].first = 0; |
| 1538 | bool __do_repeat = 0 < __max_; |
| 1539 | bool __do_alt = 0 >= __min_; |
| 1540 | if (__do_repeat && __do_alt) |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1541 | __s.__do_ = __state::__split; |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 1542 | else if (__do_repeat) |
| 1543 | { |
| 1544 | __s.__do_ = __state::__accept_but_not_consume; |
| 1545 | __s.__node_ = this->first(); |
| 1546 | __init_repeat(__s); |
| 1547 | } |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1548 | else |
| 1549 | { |
| 1550 | __s.__do_ = __state::__accept_but_not_consume; |
| 1551 | __s.__node_ = this->second(); |
| 1552 | } |
| 1553 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1554 | } |
| 1555 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1556 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1557 | void |
| 1558 | __loop<_CharT>::__exec_split(bool __second, __state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1559 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1560 | __s.__do_ = __state::__accept_but_not_consume; |
| 1561 | if (__greedy_ != __second) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1562 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1563 | __s.__node_ = this->first(); |
| 1564 | __init_repeat(__s); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1565 | } |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1566 | else |
| 1567 | __s.__node_ = this->second(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1568 | } |
| 1569 | |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1570 | // __alternate |
| 1571 | |
| 1572 | template <class _CharT> |
| 1573 | class __alternate |
| 1574 | : public __owns_two_states<_CharT> |
| 1575 | { |
| 1576 | typedef __owns_two_states<_CharT> base; |
| 1577 | |
| 1578 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1579 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1580 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1581 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1582 | explicit __alternate(__owns_one_state<_CharT>* __s1, |
| 1583 | __owns_one_state<_CharT>* __s2) |
| 1584 | : base(__s1, __s2) {} |
| 1585 | |
| 1586 | virtual void __exec(__state& __s) const; |
| 1587 | virtual void __exec_split(bool __second, __state& __s) const; |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1588 | }; |
| 1589 | |
| 1590 | template <class _CharT> |
| 1591 | void |
| 1592 | __alternate<_CharT>::__exec(__state& __s) const |
| 1593 | { |
| 1594 | __s.__do_ = __state::__split; |
| 1595 | } |
| 1596 | |
| 1597 | template <class _CharT> |
| 1598 | void |
| 1599 | __alternate<_CharT>::__exec_split(bool __second, __state& __s) const |
| 1600 | { |
| 1601 | __s.__do_ = __state::__accept_but_not_consume; |
Howard Hinnant | 1371b2e | 2010-07-22 14:12:20 +0000 | [diff] [blame] | 1602 | if (__second) |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1603 | __s.__node_ = this->second(); |
Howard Hinnant | 1371b2e | 2010-07-22 14:12:20 +0000 | [diff] [blame] | 1604 | else |
| 1605 | __s.__node_ = this->first(); |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1606 | } |
| 1607 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1608 | // __begin_marked_subexpression |
| 1609 | |
| 1610 | template <class _CharT> |
| 1611 | class __begin_marked_subexpression |
| 1612 | : public __owns_one_state<_CharT> |
| 1613 | { |
| 1614 | typedef __owns_one_state<_CharT> base; |
| 1615 | |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1616 | unsigned __mexp_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1617 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1618 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1619 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1620 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1621 | explicit __begin_marked_subexpression(unsigned __mexp, __node<_CharT>* __s) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1622 | : base(__s), __mexp_(__mexp) {} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1623 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1624 | virtual void __exec(__state&) const; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1625 | }; |
| 1626 | |
| 1627 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1628 | void |
| 1629 | __begin_marked_subexpression<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1630 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1631 | __s.__do_ = __state::__accept_but_not_consume; |
| 1632 | __s.__sub_matches_[__mexp_-1].first = __s.__current_; |
| 1633 | __s.__node_ = this->first(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1634 | } |
| 1635 | |
| 1636 | // __end_marked_subexpression |
| 1637 | |
| 1638 | template <class _CharT> |
| 1639 | class __end_marked_subexpression |
| 1640 | : public __owns_one_state<_CharT> |
| 1641 | { |
| 1642 | typedef __owns_one_state<_CharT> base; |
| 1643 | |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1644 | unsigned __mexp_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1645 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1646 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1647 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1648 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1649 | explicit __end_marked_subexpression(unsigned __mexp, __node<_CharT>* __s) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1650 | : base(__s), __mexp_(__mexp) {} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1651 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1652 | virtual void __exec(__state&) const; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1653 | }; |
| 1654 | |
| 1655 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1656 | void |
| 1657 | __end_marked_subexpression<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1658 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1659 | __s.__do_ = __state::__accept_but_not_consume; |
| 1660 | __s.__sub_matches_[__mexp_-1].second = __s.__current_; |
| 1661 | __s.__sub_matches_[__mexp_-1].matched = true; |
| 1662 | __s.__node_ = this->first(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1663 | } |
| 1664 | |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1665 | // __back_ref |
| 1666 | |
| 1667 | template <class _CharT> |
| 1668 | class __back_ref |
| 1669 | : public __owns_one_state<_CharT> |
| 1670 | { |
| 1671 | typedef __owns_one_state<_CharT> base; |
| 1672 | |
| 1673 | unsigned __mexp_; |
| 1674 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1675 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1676 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1677 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1678 | explicit __back_ref(unsigned __mexp, __node<_CharT>* __s) |
| 1679 | : base(__s), __mexp_(__mexp) {} |
| 1680 | |
| 1681 | virtual void __exec(__state&) const; |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1682 | }; |
| 1683 | |
| 1684 | template <class _CharT> |
| 1685 | void |
| 1686 | __back_ref<_CharT>::__exec(__state& __s) const |
| 1687 | { |
| 1688 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1689 | if (__sm.matched) |
| 1690 | { |
| 1691 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1692 | if (__s.__last_ - __s.__current_ >= __len && |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1693 | _VSTD::equal(__sm.first, __sm.second, __s.__current_)) |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1694 | { |
| 1695 | __s.__do_ = __state::__accept_but_not_consume; |
| 1696 | __s.__current_ += __len; |
| 1697 | __s.__node_ = this->first(); |
| 1698 | } |
| 1699 | else |
| 1700 | { |
| 1701 | __s.__do_ = __state::__reject; |
| 1702 | __s.__node_ = nullptr; |
| 1703 | } |
| 1704 | } |
| 1705 | else |
| 1706 | { |
| 1707 | __s.__do_ = __state::__reject; |
| 1708 | __s.__node_ = nullptr; |
| 1709 | } |
| 1710 | } |
| 1711 | |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1712 | // __back_ref_icase |
| 1713 | |
| 1714 | template <class _CharT, class _Traits> |
| 1715 | class __back_ref_icase |
| 1716 | : public __owns_one_state<_CharT> |
| 1717 | { |
| 1718 | typedef __owns_one_state<_CharT> base; |
| 1719 | |
| 1720 | _Traits __traits_; |
| 1721 | unsigned __mexp_; |
| 1722 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1723 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1724 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1725 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1726 | explicit __back_ref_icase(const _Traits& __traits, unsigned __mexp, |
| 1727 | __node<_CharT>* __s) |
| 1728 | : base(__s), __traits_(__traits), __mexp_(__mexp) {} |
| 1729 | |
| 1730 | virtual void __exec(__state&) const; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1731 | }; |
| 1732 | |
| 1733 | template <class _CharT, class _Traits> |
| 1734 | void |
| 1735 | __back_ref_icase<_CharT, _Traits>::__exec(__state& __s) const |
| 1736 | { |
| 1737 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1738 | if (__sm.matched) |
| 1739 | { |
| 1740 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1741 | if (__s.__last_ - __s.__current_ >= __len) |
| 1742 | { |
| 1743 | for (ptrdiff_t __i = 0; __i < __len; ++__i) |
| 1744 | { |
| 1745 | if (__traits_.translate_nocase(__sm.first[__i]) != |
| 1746 | __traits_.translate_nocase(__s.__current_[__i])) |
| 1747 | goto __not_equal; |
| 1748 | } |
| 1749 | __s.__do_ = __state::__accept_but_not_consume; |
| 1750 | __s.__current_ += __len; |
| 1751 | __s.__node_ = this->first(); |
| 1752 | } |
| 1753 | else |
| 1754 | { |
| 1755 | __s.__do_ = __state::__reject; |
| 1756 | __s.__node_ = nullptr; |
| 1757 | } |
| 1758 | } |
| 1759 | else |
| 1760 | { |
| 1761 | __not_equal: |
| 1762 | __s.__do_ = __state::__reject; |
| 1763 | __s.__node_ = nullptr; |
| 1764 | } |
| 1765 | } |
| 1766 | |
| 1767 | // __back_ref_collate |
| 1768 | |
| 1769 | template <class _CharT, class _Traits> |
| 1770 | class __back_ref_collate |
| 1771 | : public __owns_one_state<_CharT> |
| 1772 | { |
| 1773 | typedef __owns_one_state<_CharT> base; |
| 1774 | |
| 1775 | _Traits __traits_; |
| 1776 | unsigned __mexp_; |
| 1777 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1778 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1779 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1780 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1781 | explicit __back_ref_collate(const _Traits& __traits, unsigned __mexp, |
| 1782 | __node<_CharT>* __s) |
| 1783 | : base(__s), __traits_(__traits), __mexp_(__mexp) {} |
| 1784 | |
| 1785 | virtual void __exec(__state&) const; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1786 | }; |
| 1787 | |
| 1788 | template <class _CharT, class _Traits> |
| 1789 | void |
| 1790 | __back_ref_collate<_CharT, _Traits>::__exec(__state& __s) const |
| 1791 | { |
| 1792 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1793 | if (__sm.matched) |
| 1794 | { |
| 1795 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1796 | if (__s.__last_ - __s.__current_ >= __len) |
| 1797 | { |
| 1798 | for (ptrdiff_t __i = 0; __i < __len; ++__i) |
| 1799 | { |
| 1800 | if (__traits_.translate(__sm.first[__i]) != |
| 1801 | __traits_.translate(__s.__current_[__i])) |
| 1802 | goto __not_equal; |
| 1803 | } |
| 1804 | __s.__do_ = __state::__accept_but_not_consume; |
| 1805 | __s.__current_ += __len; |
| 1806 | __s.__node_ = this->first(); |
| 1807 | } |
| 1808 | else |
| 1809 | { |
| 1810 | __s.__do_ = __state::__reject; |
| 1811 | __s.__node_ = nullptr; |
| 1812 | } |
| 1813 | } |
| 1814 | else |
| 1815 | { |
| 1816 | __not_equal: |
| 1817 | __s.__do_ = __state::__reject; |
| 1818 | __s.__node_ = nullptr; |
| 1819 | } |
| 1820 | } |
| 1821 | |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1822 | // __word_boundary |
| 1823 | |
| 1824 | template <class _CharT, class _Traits> |
| 1825 | class __word_boundary |
| 1826 | : public __owns_one_state<_CharT> |
| 1827 | { |
| 1828 | typedef __owns_one_state<_CharT> base; |
| 1829 | |
| 1830 | _Traits __traits_; |
| 1831 | bool __invert_; |
| 1832 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1833 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1834 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1835 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1836 | explicit __word_boundary(const _Traits& __traits, bool __invert, |
| 1837 | __node<_CharT>* __s) |
| 1838 | : base(__s), __traits_(__traits), __invert_(__invert) {} |
| 1839 | |
| 1840 | virtual void __exec(__state&) const; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1841 | }; |
| 1842 | |
| 1843 | template <class _CharT, class _Traits> |
| 1844 | void |
| 1845 | __word_boundary<_CharT, _Traits>::__exec(__state& __s) const |
| 1846 | { |
| 1847 | bool __is_word_b = false; |
| 1848 | if (__s.__first_ != __s.__last_) |
| 1849 | { |
| 1850 | if (__s.__current_ == __s.__last_) |
| 1851 | { |
| 1852 | if (!(__s.__flags_ & regex_constants::match_not_eow)) |
| 1853 | { |
| 1854 | _CharT __c = __s.__current_[-1]; |
| 1855 | __is_word_b = __c == '_' || |
| 1856 | __traits_.isctype(__c, ctype_base::alnum); |
| 1857 | } |
| 1858 | } |
Howard Hinnant | f3dcca0 | 2010-07-29 15:17:28 +0000 | [diff] [blame] | 1859 | else if (__s.__current_ == __s.__first_ && |
| 1860 | !(__s.__flags_ & regex_constants::match_prev_avail)) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1861 | { |
| 1862 | if (!(__s.__flags_ & regex_constants::match_not_bow)) |
| 1863 | { |
| 1864 | _CharT __c = *__s.__current_; |
| 1865 | __is_word_b = __c == '_' || |
| 1866 | __traits_.isctype(__c, ctype_base::alnum); |
| 1867 | } |
| 1868 | } |
| 1869 | else |
| 1870 | { |
| 1871 | _CharT __c1 = __s.__current_[-1]; |
| 1872 | _CharT __c2 = *__s.__current_; |
| 1873 | bool __is_c1_b = __c1 == '_' || |
| 1874 | __traits_.isctype(__c1, ctype_base::alnum); |
| 1875 | bool __is_c2_b = __c2 == '_' || |
| 1876 | __traits_.isctype(__c2, ctype_base::alnum); |
| 1877 | __is_word_b = __is_c1_b != __is_c2_b; |
| 1878 | } |
| 1879 | } |
| 1880 | if (__is_word_b != __invert_) |
| 1881 | { |
| 1882 | __s.__do_ = __state::__accept_but_not_consume; |
| 1883 | __s.__node_ = this->first(); |
| 1884 | } |
| 1885 | else |
| 1886 | { |
| 1887 | __s.__do_ = __state::__reject; |
| 1888 | __s.__node_ = nullptr; |
| 1889 | } |
| 1890 | } |
| 1891 | |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 1892 | // __l_anchor |
| 1893 | |
| 1894 | template <class _CharT> |
| 1895 | class __l_anchor |
| 1896 | : public __owns_one_state<_CharT> |
| 1897 | { |
| 1898 | typedef __owns_one_state<_CharT> base; |
| 1899 | |
| 1900 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1901 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 1902 | |
| 1903 | _LIBCPP_INLINE_VISIBILITY |
| 1904 | __l_anchor(__node<_CharT>* __s) |
| 1905 | : base(__s) {} |
| 1906 | |
| 1907 | virtual void __exec(__state&) const; |
| 1908 | }; |
| 1909 | |
| 1910 | template <class _CharT> |
| 1911 | void |
| 1912 | __l_anchor<_CharT>::__exec(__state& __s) const |
| 1913 | { |
| 1914 | if (__s.__at_first_ && __s.__current_ == __s.__first_) |
| 1915 | { |
| 1916 | __s.__do_ = __state::__accept_but_not_consume; |
| 1917 | __s.__node_ = this->first(); |
| 1918 | } |
| 1919 | else |
| 1920 | { |
| 1921 | __s.__do_ = __state::__reject; |
| 1922 | __s.__node_ = nullptr; |
| 1923 | } |
| 1924 | } |
| 1925 | |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 1926 | // __r_anchor |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1927 | |
| 1928 | template <class _CharT> |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 1929 | class __r_anchor |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1930 | : public __owns_one_state<_CharT> |
| 1931 | { |
| 1932 | typedef __owns_one_state<_CharT> base; |
| 1933 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1934 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1935 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1936 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1937 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1938 | __r_anchor(__node<_CharT>* __s) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 1939 | : base(__s) {} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1940 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1941 | virtual void __exec(__state&) const; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1942 | }; |
| 1943 | |
| 1944 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1945 | void |
| 1946 | __r_anchor<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1947 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1948 | if (__s.__current_ == __s.__last_) |
| 1949 | { |
| 1950 | __s.__do_ = __state::__accept_but_not_consume; |
| 1951 | __s.__node_ = this->first(); |
| 1952 | } |
| 1953 | else |
| 1954 | { |
| 1955 | __s.__do_ = __state::__reject; |
| 1956 | __s.__node_ = nullptr; |
| 1957 | } |
| 1958 | } |
| 1959 | |
| 1960 | // __match_any |
| 1961 | |
| 1962 | template <class _CharT> |
| 1963 | class __match_any |
| 1964 | : public __owns_one_state<_CharT> |
| 1965 | { |
| 1966 | typedef __owns_one_state<_CharT> base; |
| 1967 | |
| 1968 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1969 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1970 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1971 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1972 | __match_any(__node<_CharT>* __s) |
| 1973 | : base(__s) {} |
| 1974 | |
| 1975 | virtual void __exec(__state&) const; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1976 | }; |
| 1977 | |
| 1978 | template <class _CharT> |
| 1979 | void |
| 1980 | __match_any<_CharT>::__exec(__state& __s) const |
| 1981 | { |
| 1982 | if (__s.__current_ != __s.__last_ && *__s.__current_ != 0) |
| 1983 | { |
| 1984 | __s.__do_ = __state::__accept_and_consume; |
| 1985 | ++__s.__current_; |
| 1986 | __s.__node_ = this->first(); |
| 1987 | } |
| 1988 | else |
| 1989 | { |
| 1990 | __s.__do_ = __state::__reject; |
| 1991 | __s.__node_ = nullptr; |
| 1992 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1993 | } |
| 1994 | |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1995 | // __match_any_but_newline |
| 1996 | |
| 1997 | template <class _CharT> |
| 1998 | class __match_any_but_newline |
| 1999 | : public __owns_one_state<_CharT> |
| 2000 | { |
| 2001 | typedef __owns_one_state<_CharT> base; |
| 2002 | |
| 2003 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2004 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2005 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2006 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2007 | __match_any_but_newline(__node<_CharT>* __s) |
| 2008 | : base(__s) {} |
| 2009 | |
| 2010 | virtual void __exec(__state&) const; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2011 | }; |
| 2012 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2013 | // __match_char |
| 2014 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2015 | template <class _CharT> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2016 | class __match_char |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2017 | : public __owns_one_state<_CharT> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2018 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2019 | typedef __owns_one_state<_CharT> base; |
| 2020 | |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2021 | _CharT __c_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2022 | |
| 2023 | __match_char(const __match_char&); |
| 2024 | __match_char& operator=(const __match_char&); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2025 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2026 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2027 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2028 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2029 | __match_char(_CharT __c, __node<_CharT>* __s) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2030 | : base(__s), __c_(__c) {} |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2031 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2032 | virtual void __exec(__state&) const; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2033 | }; |
| 2034 | |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2035 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2036 | void |
| 2037 | __match_char<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2038 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2039 | if (__s.__current_ != __s.__last_ && *__s.__current_ == __c_) |
| 2040 | { |
| 2041 | __s.__do_ = __state::__accept_and_consume; |
| 2042 | ++__s.__current_; |
| 2043 | __s.__node_ = this->first(); |
| 2044 | } |
| 2045 | else |
| 2046 | { |
| 2047 | __s.__do_ = __state::__reject; |
| 2048 | __s.__node_ = nullptr; |
| 2049 | } |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2050 | } |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2051 | |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2052 | // __match_char_icase |
| 2053 | |
| 2054 | template <class _CharT, class _Traits> |
| 2055 | class __match_char_icase |
| 2056 | : public __owns_one_state<_CharT> |
| 2057 | { |
| 2058 | typedef __owns_one_state<_CharT> base; |
| 2059 | |
| 2060 | _Traits __traits_; |
| 2061 | _CharT __c_; |
| 2062 | |
| 2063 | __match_char_icase(const __match_char_icase&); |
| 2064 | __match_char_icase& operator=(const __match_char_icase&); |
| 2065 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2066 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2067 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2068 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2069 | __match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s) |
| 2070 | : base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {} |
| 2071 | |
| 2072 | virtual void __exec(__state&) const; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2073 | }; |
| 2074 | |
| 2075 | template <class _CharT, class _Traits> |
| 2076 | void |
| 2077 | __match_char_icase<_CharT, _Traits>::__exec(__state& __s) const |
| 2078 | { |
| 2079 | if (__s.__current_ != __s.__last_ && |
| 2080 | __traits_.translate_nocase(*__s.__current_) == __c_) |
| 2081 | { |
| 2082 | __s.__do_ = __state::__accept_and_consume; |
| 2083 | ++__s.__current_; |
| 2084 | __s.__node_ = this->first(); |
| 2085 | } |
| 2086 | else |
| 2087 | { |
| 2088 | __s.__do_ = __state::__reject; |
| 2089 | __s.__node_ = nullptr; |
| 2090 | } |
| 2091 | } |
| 2092 | |
| 2093 | // __match_char_collate |
| 2094 | |
| 2095 | template <class _CharT, class _Traits> |
| 2096 | class __match_char_collate |
| 2097 | : public __owns_one_state<_CharT> |
| 2098 | { |
| 2099 | typedef __owns_one_state<_CharT> base; |
| 2100 | |
| 2101 | _Traits __traits_; |
| 2102 | _CharT __c_; |
| 2103 | |
| 2104 | __match_char_collate(const __match_char_collate&); |
| 2105 | __match_char_collate& operator=(const __match_char_collate&); |
| 2106 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2107 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2108 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2109 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2110 | __match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s) |
| 2111 | : base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {} |
| 2112 | |
| 2113 | virtual void __exec(__state&) const; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2114 | }; |
| 2115 | |
| 2116 | template <class _CharT, class _Traits> |
| 2117 | void |
| 2118 | __match_char_collate<_CharT, _Traits>::__exec(__state& __s) const |
| 2119 | { |
| 2120 | if (__s.__current_ != __s.__last_ && |
| 2121 | __traits_.translate(*__s.__current_) == __c_) |
| 2122 | { |
| 2123 | __s.__do_ = __state::__accept_and_consume; |
| 2124 | ++__s.__current_; |
| 2125 | __s.__node_ = this->first(); |
| 2126 | } |
| 2127 | else |
| 2128 | { |
| 2129 | __s.__do_ = __state::__reject; |
| 2130 | __s.__node_ = nullptr; |
| 2131 | } |
| 2132 | } |
| 2133 | |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2134 | // __bracket_expression |
| 2135 | |
| 2136 | template <class _CharT, class _Traits> |
| 2137 | class __bracket_expression |
| 2138 | : public __owns_one_state<_CharT> |
| 2139 | { |
| 2140 | typedef __owns_one_state<_CharT> base; |
| 2141 | typedef typename _Traits::string_type string_type; |
| 2142 | |
| 2143 | _Traits __traits_; |
| 2144 | vector<_CharT> __chars_; |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2145 | vector<_CharT> __neg_chars_; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2146 | vector<pair<string_type, string_type> > __ranges_; |
| 2147 | vector<pair<_CharT, _CharT> > __digraphs_; |
| 2148 | vector<string_type> __equivalences_; |
| 2149 | ctype_base::mask __mask_; |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2150 | ctype_base::mask __neg_mask_; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2151 | bool __negate_; |
| 2152 | bool __icase_; |
| 2153 | bool __collate_; |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2154 | bool __might_have_digraph_; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2155 | |
| 2156 | __bracket_expression(const __bracket_expression&); |
| 2157 | __bracket_expression& operator=(const __bracket_expression&); |
| 2158 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2159 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2160 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2161 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2162 | __bracket_expression(const _Traits& __traits, __node<_CharT>* __s, |
| 2163 | bool __negate, bool __icase, bool __collate) |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2164 | : base(__s), __traits_(__traits), __mask_(), __neg_mask_(), |
| 2165 | __negate_(__negate), __icase_(__icase), __collate_(__collate), |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2166 | __might_have_digraph_(__traits_.getloc().name() != "C") {} |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2167 | |
| 2168 | virtual void __exec(__state&) const; |
| 2169 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2170 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2171 | bool __negated() const {return __negate_;} |
| 2172 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2173 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2174 | void __add_char(_CharT __c) |
| 2175 | { |
| 2176 | if (__icase_) |
| 2177 | __chars_.push_back(__traits_.translate_nocase(__c)); |
| 2178 | else if (__collate_) |
| 2179 | __chars_.push_back(__traits_.translate(__c)); |
| 2180 | else |
| 2181 | __chars_.push_back(__c); |
| 2182 | } |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2183 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2184 | void __add_neg_char(_CharT __c) |
| 2185 | { |
| 2186 | if (__icase_) |
| 2187 | __neg_chars_.push_back(__traits_.translate_nocase(__c)); |
| 2188 | else if (__collate_) |
| 2189 | __neg_chars_.push_back(__traits_.translate(__c)); |
| 2190 | else |
| 2191 | __neg_chars_.push_back(__c); |
| 2192 | } |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2193 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2194 | void __add_range(string_type __b, string_type __e) |
| 2195 | { |
| 2196 | if (__collate_) |
| 2197 | { |
| 2198 | if (__icase_) |
| 2199 | { |
| 2200 | for (size_t __i = 0; __i < __b.size(); ++__i) |
| 2201 | __b[__i] = __traits_.translate_nocase(__b[__i]); |
| 2202 | for (size_t __i = 0; __i < __e.size(); ++__i) |
| 2203 | __e[__i] = __traits_.translate_nocase(__e[__i]); |
| 2204 | } |
| 2205 | else |
| 2206 | { |
| 2207 | for (size_t __i = 0; __i < __b.size(); ++__i) |
| 2208 | __b[__i] = __traits_.translate(__b[__i]); |
| 2209 | for (size_t __i = 0; __i < __e.size(); ++__i) |
| 2210 | __e[__i] = __traits_.translate(__e[__i]); |
| 2211 | } |
| 2212 | __ranges_.push_back(make_pair( |
| 2213 | __traits_.transform(__b.begin(), __b.end()), |
| 2214 | __traits_.transform(__e.begin(), __e.end()))); |
| 2215 | } |
| 2216 | else |
| 2217 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2218 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2219 | if (__b.size() != 1 || __e.size() != 1) |
| 2220 | throw regex_error(regex_constants::error_collate); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2221 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2222 | if (__icase_) |
| 2223 | { |
| 2224 | __b[0] = __traits_.translate_nocase(__b[0]); |
| 2225 | __e[0] = __traits_.translate_nocase(__e[0]); |
| 2226 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2227 | __ranges_.push_back(make_pair(_VSTD::move(__b), _VSTD::move(__e))); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2228 | } |
| 2229 | } |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2230 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2231 | void __add_digraph(_CharT __c1, _CharT __c2) |
| 2232 | { |
| 2233 | if (__icase_) |
| 2234 | __digraphs_.push_back(make_pair(__traits_.translate_nocase(__c1), |
| 2235 | __traits_.translate_nocase(__c2))); |
| 2236 | else if (__collate_) |
| 2237 | __digraphs_.push_back(make_pair(__traits_.translate(__c1), |
| 2238 | __traits_.translate(__c2))); |
| 2239 | else |
| 2240 | __digraphs_.push_back(make_pair(__c1, __c2)); |
| 2241 | } |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2242 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2243 | void __add_equivalence(const string_type& __s) |
| 2244 | {__equivalences_.push_back(__s);} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2245 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2246 | void __add_class(ctype_base::mask __mask) |
| 2247 | {__mask_ |= __mask;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2248 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2249 | void __add_neg_class(ctype_base::mask __mask) |
| 2250 | {__neg_mask_ |= __mask;} |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2251 | }; |
| 2252 | |
| 2253 | template <class _CharT, class _Traits> |
| 2254 | void |
| 2255 | __bracket_expression<_CharT, _Traits>::__exec(__state& __s) const |
| 2256 | { |
| 2257 | bool __found = false; |
| 2258 | unsigned __consumed = 0; |
| 2259 | if (__s.__current_ != __s.__last_) |
| 2260 | { |
| 2261 | ++__consumed; |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2262 | if (__might_have_digraph_) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2263 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2264 | const _CharT* __next = _VSTD::next(__s.__current_); |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2265 | if (__next != __s.__last_) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2266 | { |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2267 | pair<_CharT, _CharT> __ch2(*__s.__current_, *__next); |
| 2268 | if (__icase_) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2269 | { |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2270 | __ch2.first = __traits_.translate_nocase(__ch2.first); |
| 2271 | __ch2.second = __traits_.translate_nocase(__ch2.second); |
| 2272 | } |
| 2273 | else if (__collate_) |
| 2274 | { |
| 2275 | __ch2.first = __traits_.translate(__ch2.first); |
| 2276 | __ch2.second = __traits_.translate(__ch2.second); |
| 2277 | } |
| 2278 | if (!__traits_.lookup_collatename(&__ch2.first, &__ch2.first+2).empty()) |
| 2279 | { |
| 2280 | // __ch2 is a digraph in this locale |
| 2281 | ++__consumed; |
| 2282 | for (size_t __i = 0; __i < __digraphs_.size(); ++__i) |
| 2283 | { |
| 2284 | if (__ch2 == __digraphs_[__i]) |
| 2285 | { |
| 2286 | __found = true; |
| 2287 | goto __exit; |
| 2288 | } |
| 2289 | } |
| 2290 | if (__collate_ && !__ranges_.empty()) |
| 2291 | { |
| 2292 | string_type __s2 = __traits_.transform(&__ch2.first, |
| 2293 | &__ch2.first + 2); |
| 2294 | for (size_t __i = 0; __i < __ranges_.size(); ++__i) |
| 2295 | { |
| 2296 | if (__ranges_[__i].first <= __s2 && |
| 2297 | __s2 <= __ranges_[__i].second) |
| 2298 | { |
| 2299 | __found = true; |
| 2300 | goto __exit; |
| 2301 | } |
| 2302 | } |
| 2303 | } |
| 2304 | if (!__equivalences_.empty()) |
| 2305 | { |
| 2306 | string_type __s2 = __traits_.transform_primary(&__ch2.first, |
| 2307 | &__ch2.first + 2); |
| 2308 | for (size_t __i = 0; __i < __equivalences_.size(); ++__i) |
| 2309 | { |
| 2310 | if (__s2 == __equivalences_[__i]) |
| 2311 | { |
| 2312 | __found = true; |
| 2313 | goto __exit; |
| 2314 | } |
| 2315 | } |
| 2316 | } |
| 2317 | if (__traits_.isctype(__ch2.first, __mask_) && |
| 2318 | __traits_.isctype(__ch2.second, __mask_)) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2319 | { |
| 2320 | __found = true; |
| 2321 | goto __exit; |
| 2322 | } |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2323 | if (!__traits_.isctype(__ch2.first, __neg_mask_) && |
| 2324 | !__traits_.isctype(__ch2.second, __neg_mask_)) |
| 2325 | { |
| 2326 | __found = true; |
| 2327 | goto __exit; |
| 2328 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2329 | goto __exit; |
| 2330 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2331 | } |
| 2332 | } |
| 2333 | // test *__s.__current_ as not a digraph |
| 2334 | _CharT __ch = *__s.__current_; |
| 2335 | if (__icase_) |
| 2336 | __ch = __traits_.translate_nocase(__ch); |
| 2337 | else if (__collate_) |
| 2338 | __ch = __traits_.translate(__ch); |
| 2339 | for (size_t __i = 0; __i < __chars_.size(); ++__i) |
| 2340 | { |
| 2341 | if (__ch == __chars_[__i]) |
| 2342 | { |
| 2343 | __found = true; |
| 2344 | goto __exit; |
| 2345 | } |
| 2346 | } |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2347 | if (!__neg_chars_.empty()) |
| 2348 | { |
| 2349 | for (size_t __i = 0; __i < __neg_chars_.size(); ++__i) |
| 2350 | { |
| 2351 | if (__ch == __neg_chars_[__i]) |
| 2352 | goto __is_neg_char; |
| 2353 | } |
| 2354 | __found = true; |
| 2355 | goto __exit; |
| 2356 | } |
| 2357 | __is_neg_char: |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2358 | if (!__ranges_.empty()) |
| 2359 | { |
| 2360 | string_type __s2 = __collate_ ? |
| 2361 | __traits_.transform(&__ch, &__ch + 1) : |
| 2362 | string_type(1, __ch); |
| 2363 | for (size_t __i = 0; __i < __ranges_.size(); ++__i) |
| 2364 | { |
| 2365 | if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second) |
| 2366 | { |
| 2367 | __found = true; |
| 2368 | goto __exit; |
| 2369 | } |
| 2370 | } |
| 2371 | } |
| 2372 | if (!__equivalences_.empty()) |
| 2373 | { |
| 2374 | string_type __s2 = __traits_.transform_primary(&__ch, &__ch + 1); |
| 2375 | for (size_t __i = 0; __i < __equivalences_.size(); ++__i) |
| 2376 | { |
| 2377 | if (__s2 == __equivalences_[__i]) |
| 2378 | { |
| 2379 | __found = true; |
| 2380 | goto __exit; |
| 2381 | } |
| 2382 | } |
| 2383 | } |
| 2384 | if (__traits_.isctype(__ch, __mask_)) |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2385 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2386 | __found = true; |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2387 | goto __exit; |
| 2388 | } |
| 2389 | if (__neg_mask_ && !__traits_.isctype(__ch, __neg_mask_)) |
| 2390 | { |
| 2391 | __found = true; |
| 2392 | goto __exit; |
| 2393 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2394 | } |
| 2395 | else |
| 2396 | __found = __negate_; // force reject |
| 2397 | __exit: |
| 2398 | if (__found != __negate_) |
| 2399 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2400 | __s.__do_ = __state::__accept_and_consume; |
| 2401 | __s.__current_ += __consumed; |
| 2402 | __s.__node_ = this->first(); |
| 2403 | } |
| 2404 | else |
| 2405 | { |
| 2406 | __s.__do_ = __state::__reject; |
| 2407 | __s.__node_ = nullptr; |
| 2408 | } |
| 2409 | } |
| 2410 | |
Howard Hinnant | 2b1b2d4 | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 2411 | template <class _CharT, class _Traits> class __lookahead; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2412 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2413 | template <class _CharT, class _Traits = regex_traits<_CharT> > |
Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame^] | 2414 | class _LIBCPP_TYPE_VIS basic_regex |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2415 | { |
| 2416 | public: |
| 2417 | // types: |
| 2418 | typedef _CharT value_type; |
| 2419 | typedef regex_constants::syntax_option_type flag_type; |
| 2420 | typedef typename _Traits::locale_type locale_type; |
| 2421 | |
| 2422 | private: |
| 2423 | _Traits __traits_; |
| 2424 | flag_type __flags_; |
| 2425 | unsigned __marked_count_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2426 | unsigned __loop_count_; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2427 | int __open_count_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2428 | shared_ptr<__empty_state<_CharT> > __start_; |
| 2429 | __owns_one_state<_CharT>* __end_; |
| 2430 | |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2431 | typedef _VSTD::__state<_CharT> __state; |
| 2432 | typedef _VSTD::__node<_CharT> __node; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2433 | |
| 2434 | public: |
| 2435 | // constants: |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 2436 | static const regex_constants::syntax_option_type icase = regex_constants::icase; |
| 2437 | static const regex_constants::syntax_option_type nosubs = regex_constants::nosubs; |
| 2438 | static const regex_constants::syntax_option_type optimize = regex_constants::optimize; |
| 2439 | static const regex_constants::syntax_option_type collate = regex_constants::collate; |
| 2440 | static const regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript; |
| 2441 | static const regex_constants::syntax_option_type basic = regex_constants::basic; |
| 2442 | static const regex_constants::syntax_option_type extended = regex_constants::extended; |
| 2443 | static const regex_constants::syntax_option_type awk = regex_constants::awk; |
| 2444 | static const regex_constants::syntax_option_type grep = regex_constants::grep; |
| 2445 | static const regex_constants::syntax_option_type egrep = regex_constants::egrep; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2446 | |
| 2447 | // construct/copy/destroy: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2448 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2449 | basic_regex() |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2450 | : __flags_(), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2451 | __end_(0) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2452 | {} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2453 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2454 | explicit basic_regex(const value_type* __p, flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2455 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2456 | __end_(0) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2457 | {__parse(__p, __p + __traits_.length(__p));} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2458 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2459 | basic_regex(const value_type* __p, size_t __len, flag_type __f) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2460 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2461 | __end_(0) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2462 | {__parse(__p, __p + __len);} |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2463 | // basic_regex(const basic_regex&) = default; |
| 2464 | // basic_regex(basic_regex&&) = default; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2465 | template <class _ST, class _SA> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2466 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2467 | explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p, |
| 2468 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2469 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2470 | __end_(0) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2471 | {__parse(__p.begin(), __p.end());} |
| 2472 | template <class _ForwardIterator> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2473 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2474 | basic_regex(_ForwardIterator __first, _ForwardIterator __last, |
| 2475 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2476 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2477 | __end_(0) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2478 | {__parse(__first, __last);} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2479 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2480 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2481 | basic_regex(initializer_list<value_type> __il, |
| 2482 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2483 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2484 | __end_(0) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2485 | {__parse(__il.begin(), __il.end());} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2486 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2487 | |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2488 | // ~basic_regex() = default; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2489 | |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2490 | // basic_regex& operator=(const basic_regex&) = default; |
| 2491 | // basic_regex& operator=(basic_regex&&) = default; |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2492 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2493 | basic_regex& operator=(const value_type* __p) |
| 2494 | {return assign(__p);} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2495 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2496 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2497 | basic_regex& operator=(initializer_list<value_type> __il) |
| 2498 | {return assign(__il);} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2499 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2500 | template <class _ST, class _SA> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2501 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2502 | basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p) |
| 2503 | {return assign(__p);} |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2504 | |
| 2505 | // assign: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2506 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2507 | basic_regex& assign(const basic_regex& __that) |
| 2508 | {return *this = __that;} |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 2509 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 2510 | _LIBCPP_INLINE_VISIBILITY |
| 2511 | basic_regex& assign(basic_regex&& __that) _NOEXCEPT |
| 2512 | {return *this = _VSTD::move(__that);} |
| 2513 | #endif |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2514 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2515 | basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript) |
| 2516 | {return assign(__p, __p + __traits_.length(__p), __f);} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2517 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2518 | basic_regex& assign(const value_type* __p, size_t __len, flag_type __f) |
| 2519 | {return assign(__p, __p + __len, __f);} |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2520 | template <class _ST, class _SA> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2521 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2522 | basic_regex& assign(const basic_string<value_type, _ST, _SA>& __s, |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2523 | flag_type __f = regex_constants::ECMAScript) |
| 2524 | {return assign(__s.begin(), __s.end(), __f);} |
| 2525 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2526 | template <class _InputIterator> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2527 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2528 | typename enable_if |
| 2529 | < |
| 2530 | __is_input_iterator <_InputIterator>::value && |
| 2531 | !__is_forward_iterator<_InputIterator>::value, |
| 2532 | basic_regex& |
| 2533 | >::type |
| 2534 | assign(_InputIterator __first, _InputIterator __last, |
| 2535 | flag_type __f = regex_constants::ECMAScript) |
| 2536 | { |
| 2537 | basic_string<_CharT> __t(__first, __last); |
| 2538 | return assign(__t.begin(), __t.end(), __f); |
| 2539 | } |
| 2540 | |
| 2541 | private: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2542 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2543 | void __member_init(flag_type __f) |
| 2544 | { |
| 2545 | __flags_ = __f; |
| 2546 | __marked_count_ = 0; |
| 2547 | __loop_count_ = 0; |
| 2548 | __open_count_ = 0; |
| 2549 | __end_ = nullptr; |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2550 | } |
| 2551 | public: |
| 2552 | |
| 2553 | template <class _ForwardIterator> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2554 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2555 | typename enable_if |
| 2556 | < |
| 2557 | __is_forward_iterator<_ForwardIterator>::value, |
| 2558 | basic_regex& |
| 2559 | >::type |
| 2560 | assign(_ForwardIterator __first, _ForwardIterator __last, |
| 2561 | flag_type __f = regex_constants::ECMAScript) |
| 2562 | { |
| 2563 | __member_init(__f); |
| 2564 | __parse(__first, __last); |
Argyrios Kyrtzidis | 1dc6f7a | 2012-10-13 02:03:45 +0000 | [diff] [blame] | 2565 | return *this; |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2566 | } |
| 2567 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2568 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 2569 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2570 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2571 | basic_regex& assign(initializer_list<value_type> __il, |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2572 | flag_type __f = regex_constants::ECMAScript) |
| 2573 | {return assign(__il.begin(), __il.end(), __f);} |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2574 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2575 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 2576 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2577 | // const operations: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2578 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2579 | unsigned mark_count() const {return __marked_count_;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2580 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2581 | flag_type flags() const {return __flags_;} |
| 2582 | |
| 2583 | // locale: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2584 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2585 | locale_type imbue(locale_type __loc) |
| 2586 | { |
| 2587 | __member_init(ECMAScript); |
| 2588 | __start_.reset(); |
| 2589 | return __traits_.imbue(__loc); |
| 2590 | } |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2591 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2592 | locale_type getloc() const {return __traits_.getloc();} |
| 2593 | |
| 2594 | // swap: |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2595 | void swap(basic_regex& __r); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2596 | |
| 2597 | private: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2598 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2599 | unsigned __loop_count() const {return __loop_count_;} |
| 2600 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2601 | template <class _ForwardIterator> |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2602 | _ForwardIterator |
| 2603 | __parse(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2604 | template <class _ForwardIterator> |
| 2605 | _ForwardIterator |
| 2606 | __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2607 | template <class _ForwardIterator> |
| 2608 | _ForwardIterator |
| 2609 | __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2610 | template <class _ForwardIterator> |
| 2611 | _ForwardIterator |
| 2612 | __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2613 | template <class _ForwardIterator> |
| 2614 | _ForwardIterator |
| 2615 | __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2616 | template <class _ForwardIterator> |
| 2617 | _ForwardIterator |
| 2618 | __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2619 | template <class _ForwardIterator> |
| 2620 | _ForwardIterator |
| 2621 | __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last); |
| 2622 | template <class _ForwardIterator> |
| 2623 | _ForwardIterator |
| 2624 | __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last); |
| 2625 | template <class _ForwardIterator> |
| 2626 | _ForwardIterator |
| 2627 | __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last); |
| 2628 | template <class _ForwardIterator> |
| 2629 | _ForwardIterator |
| 2630 | __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last); |
| 2631 | template <class _ForwardIterator> |
| 2632 | _ForwardIterator |
| 2633 | __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last); |
| 2634 | template <class _ForwardIterator> |
| 2635 | _ForwardIterator |
| 2636 | __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last); |
| 2637 | template <class _ForwardIterator> |
| 2638 | _ForwardIterator |
| 2639 | __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last); |
| 2640 | template <class _ForwardIterator> |
| 2641 | _ForwardIterator |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2642 | __parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last, |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2643 | __owns_one_state<_CharT>* __s, |
| 2644 | unsigned __mexp_begin, unsigned __mexp_end); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2645 | template <class _ForwardIterator> |
| 2646 | _ForwardIterator |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 2647 | __parse_ERE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last, |
| 2648 | __owns_one_state<_CharT>* __s, |
| 2649 | unsigned __mexp_begin, unsigned __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2650 | template <class _ForwardIterator> |
| 2651 | _ForwardIterator |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2652 | __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2653 | template <class _ForwardIterator> |
| 2654 | _ForwardIterator |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2655 | __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last, |
| 2656 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2657 | template <class _ForwardIterator> |
| 2658 | _ForwardIterator |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2659 | __parse_expression_term(_ForwardIterator __first, _ForwardIterator __last, |
| 2660 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2661 | template <class _ForwardIterator> |
| 2662 | _ForwardIterator |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2663 | __parse_equivalence_class(_ForwardIterator __first, _ForwardIterator __last, |
| 2664 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2665 | template <class _ForwardIterator> |
| 2666 | _ForwardIterator |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2667 | __parse_character_class(_ForwardIterator __first, _ForwardIterator __last, |
| 2668 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2669 | template <class _ForwardIterator> |
| 2670 | _ForwardIterator |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2671 | __parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last, |
| 2672 | basic_string<_CharT>& __col_sym); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2673 | template <class _ForwardIterator> |
| 2674 | _ForwardIterator |
| 2675 | __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2676 | template <class _ForwardIterator> |
| 2677 | _ForwardIterator |
| 2678 | __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2679 | template <class _ForwardIterator> |
| 2680 | _ForwardIterator |
| 2681 | __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last); |
| 2682 | template <class _ForwardIterator> |
| 2683 | _ForwardIterator |
| 2684 | __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2685 | template <class _ForwardIterator> |
| 2686 | _ForwardIterator |
| 2687 | __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last); |
| 2688 | template <class _ForwardIterator> |
| 2689 | _ForwardIterator |
| 2690 | __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last); |
| 2691 | template <class _ForwardIterator> |
| 2692 | _ForwardIterator |
| 2693 | __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 2694 | template <class _ForwardIterator> |
| 2695 | _ForwardIterator |
| 2696 | __parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2697 | template <class _ForwardIterator> |
| 2698 | _ForwardIterator |
| 2699 | __parse_alternative(_ForwardIterator __first, _ForwardIterator __last); |
| 2700 | template <class _ForwardIterator> |
| 2701 | _ForwardIterator |
| 2702 | __parse_term(_ForwardIterator __first, _ForwardIterator __last); |
| 2703 | template <class _ForwardIterator> |
| 2704 | _ForwardIterator |
| 2705 | __parse_assertion(_ForwardIterator __first, _ForwardIterator __last); |
| 2706 | template <class _ForwardIterator> |
| 2707 | _ForwardIterator |
| 2708 | __parse_atom(_ForwardIterator __first, _ForwardIterator __last); |
| 2709 | template <class _ForwardIterator> |
| 2710 | _ForwardIterator |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2711 | __parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2712 | template <class _ForwardIterator> |
| 2713 | _ForwardIterator |
| 2714 | __parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2715 | template <class _ForwardIterator> |
| 2716 | _ForwardIterator |
| 2717 | __parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2718 | template <class _ForwardIterator> |
| 2719 | _ForwardIterator |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2720 | __parse_character_escape(_ForwardIterator __first, _ForwardIterator __last, |
| 2721 | basic_string<_CharT>* __str = nullptr); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2722 | template <class _ForwardIterator> |
| 2723 | _ForwardIterator |
| 2724 | __parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 856846b | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 2725 | template <class _ForwardIterator> |
| 2726 | _ForwardIterator |
| 2727 | __parse_grep(_ForwardIterator __first, _ForwardIterator __last); |
| 2728 | template <class _ForwardIterator> |
| 2729 | _ForwardIterator |
| 2730 | __parse_egrep(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2731 | template <class _ForwardIterator> |
| 2732 | _ForwardIterator |
| 2733 | __parse_class_escape(_ForwardIterator __first, _ForwardIterator __last, |
| 2734 | basic_string<_CharT>& __str, |
| 2735 | __bracket_expression<_CharT, _Traits>* __ml); |
| 2736 | template <class _ForwardIterator> |
| 2737 | _ForwardIterator |
| 2738 | __parse_awk_escape(_ForwardIterator __first, _ForwardIterator __last, |
| 2739 | basic_string<_CharT>* __str = nullptr); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2740 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2741 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2742 | void __push_l_anchor(); |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2743 | void __push_r_anchor(); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2744 | void __push_match_any(); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2745 | void __push_match_any_but_newline(); |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2746 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2747 | void __push_greedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s, |
| 2748 | unsigned __mexp_begin = 0, unsigned __mexp_end = 0) |
| 2749 | {__push_loop(__min, numeric_limits<size_t>::max(), __s, |
| 2750 | __mexp_begin, __mexp_end);} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2751 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2752 | void __push_nongreedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s, |
| 2753 | unsigned __mexp_begin = 0, unsigned __mexp_end = 0) |
| 2754 | {__push_loop(__min, numeric_limits<size_t>::max(), __s, |
| 2755 | __mexp_begin, __mexp_end, false);} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2756 | void __push_loop(size_t __min, size_t __max, __owns_one_state<_CharT>* __s, |
| 2757 | size_t __mexp_begin = 0, size_t __mexp_end = 0, |
| 2758 | bool __greedy = true); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2759 | __bracket_expression<_CharT, _Traits>* __start_matching_list(bool __negate); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2760 | void __push_char(value_type __c); |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 2761 | void __push_back_ref(int __i); |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 2762 | void __push_alternation(__owns_one_state<_CharT>* __sa, |
| 2763 | __owns_one_state<_CharT>* __sb); |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2764 | void __push_begin_marked_subexpression(); |
| 2765 | void __push_end_marked_subexpression(unsigned); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 2766 | void __push_empty(); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2767 | void __push_word_boundary(bool); |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2768 | void __push_lookahead(const basic_regex&, bool); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2769 | |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2770 | template <class _Allocator> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2771 | bool |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2772 | __search(const _CharT* __first, const _CharT* __last, |
| 2773 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2774 | regex_constants::match_flag_type __flags) const; |
| 2775 | |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2776 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2777 | bool |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2778 | __match_at_start(const _CharT* __first, const _CharT* __last, |
| 2779 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2780 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2781 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2782 | bool |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2783 | __match_at_start_ecma(const _CharT* __first, const _CharT* __last, |
| 2784 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2785 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2786 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2787 | bool |
| 2788 | __match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last, |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2789 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2790 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2791 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2792 | bool |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2793 | __match_at_start_posix_subs(const _CharT* __first, const _CharT* __last, |
| 2794 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2795 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2796 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2797 | template <class _Bp, class _Ap, class _Cp, class _Tp> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2798 | friend |
| 2799 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2800 | regex_search(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&, |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2801 | regex_constants::match_flag_type); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2802 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2803 | template <class _Ap, class _Cp, class _Tp> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2804 | friend |
| 2805 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2806 | regex_search(const _Cp*, const _Cp*, match_results<const _Cp*, _Ap>&, |
| 2807 | const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2808 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2809 | template <class _Bp, class _Cp, class _Tp> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2810 | friend |
| 2811 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2812 | regex_search(_Bp, _Bp, const basic_regex<_Cp, _Tp>&, |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2813 | regex_constants::match_flag_type); |
| 2814 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2815 | template <class _Cp, class _Tp> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2816 | friend |
| 2817 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2818 | regex_search(const _Cp*, const _Cp*, |
| 2819 | const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2820 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2821 | template <class _Cp, class _Ap, class _Tp> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2822 | friend |
| 2823 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2824 | regex_search(const _Cp*, match_results<const _Cp*, _Ap>&, const basic_regex<_Cp, _Tp>&, |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2825 | regex_constants::match_flag_type); |
| 2826 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2827 | template <class _ST, class _SA, class _Cp, class _Tp> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2828 | friend |
| 2829 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2830 | regex_search(const basic_string<_Cp, _ST, _SA>& __s, |
| 2831 | const basic_regex<_Cp, _Tp>& __e, |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2832 | regex_constants::match_flag_type __flags); |
| 2833 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2834 | template <class _ST, class _SA, class _Ap, class _Cp, class _Tp> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2835 | friend |
| 2836 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2837 | regex_search(const basic_string<_Cp, _ST, _SA>& __s, |
| 2838 | match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&, |
| 2839 | const basic_regex<_Cp, _Tp>& __e, |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2840 | regex_constants::match_flag_type __flags); |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2841 | |
| 2842 | template <class, class> friend class __lookahead; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2843 | }; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2844 | |
| 2845 | template <class _CharT, class _Traits> |
Howard Hinnant | 0a69fa1 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2846 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::icase; |
| 2847 | template <class _CharT, class _Traits> |
| 2848 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::nosubs; |
| 2849 | template <class _CharT, class _Traits> |
| 2850 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::optimize; |
| 2851 | template <class _CharT, class _Traits> |
| 2852 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::collate; |
| 2853 | template <class _CharT, class _Traits> |
| 2854 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::ECMAScript; |
| 2855 | template <class _CharT, class _Traits> |
| 2856 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::basic; |
| 2857 | template <class _CharT, class _Traits> |
| 2858 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::extended; |
| 2859 | template <class _CharT, class _Traits> |
| 2860 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::awk; |
| 2861 | template <class _CharT, class _Traits> |
| 2862 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::grep; |
| 2863 | template <class _CharT, class _Traits> |
| 2864 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::egrep; |
| 2865 | |
| 2866 | template <class _CharT, class _Traits> |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2867 | void |
| 2868 | basic_regex<_CharT, _Traits>::swap(basic_regex& __r) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2869 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2870 | using _VSTD::swap; |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2871 | swap(__traits_, __r.__traits_); |
| 2872 | swap(__flags_, __r.__flags_); |
| 2873 | swap(__marked_count_, __r.__marked_count_); |
| 2874 | swap(__loop_count_, __r.__loop_count_); |
| 2875 | swap(__open_count_, __r.__open_count_); |
| 2876 | swap(__start_, __r.__start_); |
| 2877 | swap(__end_, __r.__end_); |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2878 | } |
| 2879 | |
| 2880 | template <class _CharT, class _Traits> |
| 2881 | inline _LIBCPP_INLINE_VISIBILITY |
| 2882 | void |
| 2883 | swap(basic_regex<_CharT, _Traits>& __x, basic_regex<_CharT, _Traits>& __y) |
| 2884 | { |
| 2885 | return __x.swap(__y); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2886 | } |
| 2887 | |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2888 | // __lookahead |
| 2889 | |
| 2890 | template <class _CharT, class _Traits> |
| 2891 | class __lookahead |
| 2892 | : public __owns_one_state<_CharT> |
| 2893 | { |
| 2894 | typedef __owns_one_state<_CharT> base; |
| 2895 | |
| 2896 | basic_regex<_CharT, _Traits> __exp_; |
| 2897 | bool __invert_; |
| 2898 | |
| 2899 | __lookahead(const __lookahead&); |
| 2900 | __lookahead& operator=(const __lookahead&); |
| 2901 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2902 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2903 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2904 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2905 | __lookahead(const basic_regex<_CharT, _Traits>& __exp, bool __invert, __node<_CharT>* __s) |
| 2906 | : base(__s), __exp_(__exp), __invert_(__invert) {} |
| 2907 | |
| 2908 | virtual void __exec(__state&) const; |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2909 | }; |
| 2910 | |
| 2911 | template <class _CharT, class _Traits> |
| 2912 | void |
| 2913 | __lookahead<_CharT, _Traits>::__exec(__state& __s) const |
| 2914 | { |
| 2915 | match_results<const _CharT*> __m; |
| 2916 | __m.__init(1 + __exp_.mark_count(), __s.__current_, __s.__last_); |
| 2917 | bool __matched = __exp_.__match_at_start_ecma(__s.__current_, __s.__last_, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2918 | __m, |
| 2919 | __s.__flags_ | regex_constants::match_continuous, |
| 2920 | true); |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2921 | if (__matched != __invert_) |
| 2922 | { |
| 2923 | __s.__do_ = __state::__accept_but_not_consume; |
| 2924 | __s.__node_ = this->first(); |
| 2925 | } |
| 2926 | else |
| 2927 | { |
| 2928 | __s.__do_ = __state::__reject; |
| 2929 | __s.__node_ = nullptr; |
| 2930 | } |
| 2931 | } |
| 2932 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2933 | template <class _CharT, class _Traits> |
| 2934 | template <class _ForwardIterator> |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2935 | _ForwardIterator |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2936 | basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first, |
| 2937 | _ForwardIterator __last) |
| 2938 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2939 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2940 | unique_ptr<__node> __h(new __end_state<_CharT>); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2941 | __start_.reset(new __empty_state<_CharT>(__h.get())); |
| 2942 | __h.release(); |
| 2943 | __end_ = __start_.get(); |
| 2944 | } |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 2945 | switch (__flags_ & 0x1F0) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2946 | { |
| 2947 | case ECMAScript: |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2948 | __first = __parse_ecma_exp(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2949 | break; |
| 2950 | case basic: |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2951 | __first = __parse_basic_reg_exp(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2952 | break; |
| 2953 | case extended: |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2954 | case awk: |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2955 | __first = __parse_extended_reg_exp(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2956 | break; |
| 2957 | case grep: |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2958 | __first = __parse_grep(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2959 | break; |
| 2960 | case egrep: |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2961 | __first = __parse_egrep(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2962 | break; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2963 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2964 | default: |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 2965 | throw regex_error(regex_constants::__re_err_grammar); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2966 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2967 | } |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2968 | return __first; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2969 | } |
| 2970 | |
| 2971 | template <class _CharT, class _Traits> |
| 2972 | template <class _ForwardIterator> |
| 2973 | _ForwardIterator |
| 2974 | basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first, |
| 2975 | _ForwardIterator __last) |
| 2976 | { |
| 2977 | if (__first != __last) |
| 2978 | { |
| 2979 | if (*__first == '^') |
| 2980 | { |
| 2981 | __push_l_anchor(); |
| 2982 | ++__first; |
| 2983 | } |
| 2984 | if (__first != __last) |
| 2985 | { |
| 2986 | __first = __parse_RE_expression(__first, __last); |
| 2987 | if (__first != __last) |
| 2988 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2989 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2990 | if (__temp == __last && *__first == '$') |
| 2991 | { |
| 2992 | __push_r_anchor(); |
| 2993 | ++__first; |
| 2994 | } |
| 2995 | } |
| 2996 | } |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2997 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2998 | if (__first != __last) |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 2999 | throw regex_error(regex_constants::__re_err_empty); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3000 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3001 | } |
| 3002 | return __first; |
| 3003 | } |
| 3004 | |
| 3005 | template <class _CharT, class _Traits> |
| 3006 | template <class _ForwardIterator> |
| 3007 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3008 | basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first, |
| 3009 | _ForwardIterator __last) |
| 3010 | { |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3011 | __owns_one_state<_CharT>* __sa = __end_; |
| 3012 | _ForwardIterator __temp = __parse_ERE_branch(__first, __last); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3013 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3014 | if (__temp == __first) |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 3015 | throw regex_error(regex_constants::__re_err_empty); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3016 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3017 | __first = __temp; |
| 3018 | while (__first != __last && *__first == '|') |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3019 | { |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3020 | __owns_one_state<_CharT>* __sb = __end_; |
| 3021 | __temp = __parse_ERE_branch(++__first, __last); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3022 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3023 | if (__temp == __first) |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 3024 | throw regex_error(regex_constants::__re_err_empty); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3025 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3026 | __push_alternation(__sa, __sb); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3027 | __first = __temp; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3028 | } |
| 3029 | return __first; |
| 3030 | } |
| 3031 | |
| 3032 | template <class _CharT, class _Traits> |
| 3033 | template <class _ForwardIterator> |
| 3034 | _ForwardIterator |
| 3035 | basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first, |
| 3036 | _ForwardIterator __last) |
| 3037 | { |
| 3038 | _ForwardIterator __temp = __parse_ERE_expression(__first, __last); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3039 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3040 | if (__temp == __first) |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 3041 | throw regex_error(regex_constants::__re_err_empty); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3042 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3043 | do |
| 3044 | { |
| 3045 | __first = __temp; |
| 3046 | __temp = __parse_ERE_expression(__first, __last); |
| 3047 | } while (__temp != __first); |
| 3048 | return __first; |
| 3049 | } |
| 3050 | |
| 3051 | template <class _CharT, class _Traits> |
| 3052 | template <class _ForwardIterator> |
| 3053 | _ForwardIterator |
| 3054 | basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first, |
| 3055 | _ForwardIterator __last) |
| 3056 | { |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3057 | __owns_one_state<_CharT>* __e = __end_; |
| 3058 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3059 | _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last); |
| 3060 | if (__temp == __first && __temp != __last) |
| 3061 | { |
| 3062 | switch (*__temp) |
| 3063 | { |
| 3064 | case '^': |
| 3065 | __push_l_anchor(); |
| 3066 | ++__temp; |
| 3067 | break; |
| 3068 | case '$': |
| 3069 | __push_r_anchor(); |
| 3070 | ++__temp; |
| 3071 | break; |
| 3072 | case '(': |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3073 | __push_begin_marked_subexpression(); |
| 3074 | unsigned __temp_count = __marked_count_; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3075 | ++__open_count_; |
| 3076 | __temp = __parse_extended_reg_exp(++__temp, __last); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3077 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3078 | if (__temp == __last || *__temp != ')') |
| 3079 | throw regex_error(regex_constants::error_paren); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3080 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3081 | __push_end_marked_subexpression(__temp_count); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3082 | --__open_count_; |
| 3083 | ++__temp; |
| 3084 | break; |
| 3085 | } |
| 3086 | } |
| 3087 | if (__temp != __first) |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3088 | __temp = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin+1, |
| 3089 | __marked_count_+1); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3090 | __first = __temp; |
| 3091 | return __first; |
| 3092 | } |
| 3093 | |
| 3094 | template <class _CharT, class _Traits> |
| 3095 | template <class _ForwardIterator> |
| 3096 | _ForwardIterator |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3097 | basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first, |
| 3098 | _ForwardIterator __last) |
| 3099 | { |
| 3100 | while (true) |
| 3101 | { |
| 3102 | _ForwardIterator __temp = __parse_simple_RE(__first, __last); |
| 3103 | if (__temp == __first) |
| 3104 | break; |
| 3105 | __first = __temp; |
| 3106 | } |
| 3107 | return __first; |
| 3108 | } |
| 3109 | |
| 3110 | template <class _CharT, class _Traits> |
| 3111 | template <class _ForwardIterator> |
| 3112 | _ForwardIterator |
| 3113 | basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first, |
| 3114 | _ForwardIterator __last) |
| 3115 | { |
| 3116 | if (__first != __last) |
| 3117 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3118 | __owns_one_state<_CharT>* __e = __end_; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3119 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3120 | _ForwardIterator __temp = __parse_nondupl_RE(__first, __last); |
| 3121 | if (__temp != __first) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3122 | __first = __parse_RE_dupl_symbol(__temp, __last, __e, |
| 3123 | __mexp_begin+1, __marked_count_+1); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3124 | } |
| 3125 | return __first; |
| 3126 | } |
| 3127 | |
| 3128 | template <class _CharT, class _Traits> |
| 3129 | template <class _ForwardIterator> |
| 3130 | _ForwardIterator |
| 3131 | basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first, |
| 3132 | _ForwardIterator __last) |
| 3133 | { |
| 3134 | _ForwardIterator __temp = __first; |
| 3135 | __first = __parse_one_char_or_coll_elem_RE(__first, __last); |
| 3136 | if (__temp == __first) |
| 3137 | { |
| 3138 | __temp = __parse_Back_open_paren(__first, __last); |
| 3139 | if (__temp != __first) |
| 3140 | { |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3141 | __push_begin_marked_subexpression(); |
| 3142 | unsigned __temp_count = __marked_count_; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3143 | __first = __parse_RE_expression(__temp, __last); |
| 3144 | __temp = __parse_Back_close_paren(__first, __last); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3145 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3146 | if (__temp == __first) |
| 3147 | throw regex_error(regex_constants::error_paren); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3148 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3149 | __push_end_marked_subexpression(__temp_count); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3150 | __first = __temp; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3151 | } |
| 3152 | else |
| 3153 | __first = __parse_BACKREF(__first, __last); |
| 3154 | } |
| 3155 | return __first; |
| 3156 | } |
| 3157 | |
| 3158 | template <class _CharT, class _Traits> |
| 3159 | template <class _ForwardIterator> |
| 3160 | _ForwardIterator |
| 3161 | basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE( |
| 3162 | _ForwardIterator __first, |
| 3163 | _ForwardIterator __last) |
| 3164 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3165 | _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3166 | if (__temp == __first) |
| 3167 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3168 | __temp = __parse_QUOTED_CHAR(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3169 | if (__temp == __first) |
| 3170 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3171 | if (__temp != __last && *__temp == '.') |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3172 | { |
| 3173 | __push_match_any(); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3174 | ++__temp; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3175 | } |
| 3176 | else |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3177 | __temp = __parse_bracket_expression(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3178 | } |
| 3179 | } |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3180 | __first = __temp; |
| 3181 | return __first; |
| 3182 | } |
| 3183 | |
| 3184 | template <class _CharT, class _Traits> |
| 3185 | template <class _ForwardIterator> |
| 3186 | _ForwardIterator |
| 3187 | basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE( |
| 3188 | _ForwardIterator __first, |
| 3189 | _ForwardIterator __last) |
| 3190 | { |
| 3191 | _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last); |
| 3192 | if (__temp == __first) |
| 3193 | { |
| 3194 | __temp = __parse_QUOTED_CHAR_ERE(__first, __last); |
| 3195 | if (__temp == __first) |
| 3196 | { |
| 3197 | if (__temp != __last && *__temp == '.') |
| 3198 | { |
| 3199 | __push_match_any(); |
| 3200 | ++__temp; |
| 3201 | } |
| 3202 | else |
| 3203 | __temp = __parse_bracket_expression(__first, __last); |
| 3204 | } |
| 3205 | } |
| 3206 | __first = __temp; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3207 | return __first; |
| 3208 | } |
| 3209 | |
| 3210 | template <class _CharT, class _Traits> |
| 3211 | template <class _ForwardIterator> |
| 3212 | _ForwardIterator |
| 3213 | basic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first, |
| 3214 | _ForwardIterator __last) |
| 3215 | { |
| 3216 | if (__first != __last) |
| 3217 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3218 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3219 | if (__temp != __last) |
| 3220 | { |
| 3221 | if (*__first == '\\' && *__temp == '(') |
| 3222 | __first = ++__temp; |
| 3223 | } |
| 3224 | } |
| 3225 | return __first; |
| 3226 | } |
| 3227 | |
| 3228 | template <class _CharT, class _Traits> |
| 3229 | template <class _ForwardIterator> |
| 3230 | _ForwardIterator |
| 3231 | basic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first, |
| 3232 | _ForwardIterator __last) |
| 3233 | { |
| 3234 | if (__first != __last) |
| 3235 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3236 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3237 | if (__temp != __last) |
| 3238 | { |
| 3239 | if (*__first == '\\' && *__temp == ')') |
| 3240 | __first = ++__temp; |
| 3241 | } |
| 3242 | } |
| 3243 | return __first; |
| 3244 | } |
| 3245 | |
| 3246 | template <class _CharT, class _Traits> |
| 3247 | template <class _ForwardIterator> |
| 3248 | _ForwardIterator |
| 3249 | basic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first, |
| 3250 | _ForwardIterator __last) |
| 3251 | { |
| 3252 | if (__first != __last) |
| 3253 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3254 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3255 | if (__temp != __last) |
| 3256 | { |
| 3257 | if (*__first == '\\' && *__temp == '{') |
| 3258 | __first = ++__temp; |
| 3259 | } |
| 3260 | } |
| 3261 | return __first; |
| 3262 | } |
| 3263 | |
| 3264 | template <class _CharT, class _Traits> |
| 3265 | template <class _ForwardIterator> |
| 3266 | _ForwardIterator |
| 3267 | basic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first, |
| 3268 | _ForwardIterator __last) |
| 3269 | { |
| 3270 | if (__first != __last) |
| 3271 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3272 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3273 | if (__temp != __last) |
| 3274 | { |
| 3275 | if (*__first == '\\' && *__temp == '}') |
| 3276 | __first = ++__temp; |
| 3277 | } |
| 3278 | } |
| 3279 | return __first; |
| 3280 | } |
| 3281 | |
| 3282 | template <class _CharT, class _Traits> |
| 3283 | template <class _ForwardIterator> |
| 3284 | _ForwardIterator |
| 3285 | basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first, |
| 3286 | _ForwardIterator __last) |
| 3287 | { |
| 3288 | if (__first != __last) |
| 3289 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3290 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3291 | if (__temp != __last) |
| 3292 | { |
| 3293 | if (*__first == '\\' && '1' <= *__temp && *__temp <= '9') |
| 3294 | { |
| 3295 | __push_back_ref(*__temp - '0'); |
| 3296 | __first = ++__temp; |
| 3297 | } |
| 3298 | } |
| 3299 | } |
| 3300 | return __first; |
| 3301 | } |
| 3302 | |
| 3303 | template <class _CharT, class _Traits> |
| 3304 | template <class _ForwardIterator> |
| 3305 | _ForwardIterator |
| 3306 | basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first, |
| 3307 | _ForwardIterator __last) |
| 3308 | { |
| 3309 | if (__first != __last) |
| 3310 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3311 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3312 | if (__temp == __last && *__first == '$') |
| 3313 | return __first; |
| 3314 | // Not called inside a bracket |
| 3315 | if (*__first == '.' || *__first == '\\' || *__first == '[') |
| 3316 | return __first; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3317 | __push_char(*__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3318 | ++__first; |
| 3319 | } |
| 3320 | return __first; |
| 3321 | } |
| 3322 | |
| 3323 | template <class _CharT, class _Traits> |
| 3324 | template <class _ForwardIterator> |
| 3325 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3326 | basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first, |
| 3327 | _ForwardIterator __last) |
| 3328 | { |
| 3329 | if (__first != __last) |
| 3330 | { |
| 3331 | switch (*__first) |
| 3332 | { |
| 3333 | case '^': |
| 3334 | case '.': |
| 3335 | case '[': |
| 3336 | case '$': |
| 3337 | case '(': |
| 3338 | case '|': |
| 3339 | case '*': |
| 3340 | case '+': |
| 3341 | case '?': |
| 3342 | case '{': |
| 3343 | case '\\': |
| 3344 | break; |
| 3345 | case ')': |
| 3346 | if (__open_count_ == 0) |
| 3347 | { |
| 3348 | __push_char(*__first); |
| 3349 | ++__first; |
| 3350 | } |
| 3351 | break; |
| 3352 | default: |
| 3353 | __push_char(*__first); |
| 3354 | ++__first; |
| 3355 | break; |
| 3356 | } |
| 3357 | } |
| 3358 | return __first; |
| 3359 | } |
| 3360 | |
| 3361 | template <class _CharT, class _Traits> |
| 3362 | template <class _ForwardIterator> |
| 3363 | _ForwardIterator |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3364 | basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first, |
| 3365 | _ForwardIterator __last) |
| 3366 | { |
| 3367 | if (__first != __last) |
| 3368 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3369 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3370 | if (__temp != __last) |
| 3371 | { |
| 3372 | if (*__first == '\\') |
| 3373 | { |
| 3374 | switch (*__temp) |
| 3375 | { |
| 3376 | case '^': |
| 3377 | case '.': |
| 3378 | case '*': |
| 3379 | case '[': |
| 3380 | case '$': |
| 3381 | case '\\': |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3382 | __push_char(*__temp); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3383 | __first = ++__temp; |
| 3384 | break; |
| 3385 | } |
| 3386 | } |
| 3387 | } |
| 3388 | } |
| 3389 | return __first; |
| 3390 | } |
| 3391 | |
| 3392 | template <class _CharT, class _Traits> |
| 3393 | template <class _ForwardIterator> |
| 3394 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3395 | basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first, |
| 3396 | _ForwardIterator __last) |
| 3397 | { |
| 3398 | if (__first != __last) |
| 3399 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3400 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3401 | if (__temp != __last) |
| 3402 | { |
| 3403 | if (*__first == '\\') |
| 3404 | { |
| 3405 | switch (*__temp) |
| 3406 | { |
| 3407 | case '^': |
| 3408 | case '.': |
| 3409 | case '*': |
| 3410 | case '[': |
| 3411 | case '$': |
| 3412 | case '\\': |
| 3413 | case '(': |
| 3414 | case ')': |
| 3415 | case '|': |
| 3416 | case '+': |
| 3417 | case '?': |
| 3418 | case '{': |
| 3419 | __push_char(*__temp); |
| 3420 | __first = ++__temp; |
| 3421 | break; |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3422 | default: |
| 3423 | if ((__flags_ & 0x1F0) == awk) |
| 3424 | __first = __parse_awk_escape(++__first, __last); |
| 3425 | break; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3426 | } |
| 3427 | } |
| 3428 | } |
| 3429 | } |
| 3430 | return __first; |
| 3431 | } |
| 3432 | |
| 3433 | template <class _CharT, class _Traits> |
| 3434 | template <class _ForwardIterator> |
| 3435 | _ForwardIterator |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3436 | basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3437 | _ForwardIterator __last, |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3438 | __owns_one_state<_CharT>* __s, |
| 3439 | unsigned __mexp_begin, |
| 3440 | unsigned __mexp_end) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3441 | { |
| 3442 | if (__first != __last) |
| 3443 | { |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3444 | if (*__first == '*') |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3445 | { |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3446 | __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3447 | ++__first; |
| 3448 | } |
| 3449 | else |
| 3450 | { |
| 3451 | _ForwardIterator __temp = __parse_Back_open_brace(__first, __last); |
| 3452 | if (__temp != __first) |
| 3453 | { |
| 3454 | int __min = 0; |
| 3455 | __first = __temp; |
| 3456 | __temp = __parse_DUP_COUNT(__first, __last, __min); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3457 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3458 | if (__temp == __first) |
| 3459 | throw regex_error(regex_constants::error_badbrace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3460 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3461 | __first = __temp; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3462 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3463 | if (__first == __last) |
| 3464 | throw regex_error(regex_constants::error_brace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3465 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3466 | if (*__first != ',') |
| 3467 | { |
| 3468 | __temp = __parse_Back_close_brace(__first, __last); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3469 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3470 | if (__temp == __first) |
| 3471 | throw regex_error(regex_constants::error_brace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3472 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 3473 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, |
| 3474 | true); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3475 | __first = __temp; |
| 3476 | } |
| 3477 | else |
| 3478 | { |
| 3479 | ++__first; // consume ',' |
| 3480 | int __max = -1; |
| 3481 | __first = __parse_DUP_COUNT(__first, __last, __max); |
| 3482 | __temp = __parse_Back_close_brace(__first, __last); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3483 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3484 | if (__temp == __first) |
| 3485 | throw regex_error(regex_constants::error_brace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3486 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3487 | if (__max == -1) |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3488 | __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3489 | else |
| 3490 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3491 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3492 | if (__max < __min) |
| 3493 | throw regex_error(regex_constants::error_badbrace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3494 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 3495 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, |
| 3496 | true); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3497 | } |
| 3498 | __first = __temp; |
| 3499 | } |
| 3500 | } |
| 3501 | } |
| 3502 | } |
| 3503 | return __first; |
| 3504 | } |
| 3505 | |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3506 | template <class _CharT, class _Traits> |
| 3507 | template <class _ForwardIterator> |
| 3508 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3509 | basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first, |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3510 | _ForwardIterator __last, |
| 3511 | __owns_one_state<_CharT>* __s, |
| 3512 | unsigned __mexp_begin, |
| 3513 | unsigned __mexp_end) |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3514 | { |
| 3515 | if (__first != __last) |
| 3516 | { |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3517 | unsigned __grammar = __flags_ & 0x1F0; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3518 | switch (*__first) |
| 3519 | { |
| 3520 | case '*': |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3521 | ++__first; |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3522 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3523 | { |
| 3524 | ++__first; |
| 3525 | __push_nongreedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
| 3526 | } |
| 3527 | else |
| 3528 | __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3529 | break; |
| 3530 | case '+': |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3531 | ++__first; |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3532 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3533 | { |
| 3534 | ++__first; |
| 3535 | __push_nongreedy_inf_repeat(1, __s, __mexp_begin, __mexp_end); |
| 3536 | } |
| 3537 | else |
| 3538 | __push_greedy_inf_repeat(1, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3539 | break; |
| 3540 | case '?': |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3541 | ++__first; |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3542 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3543 | { |
| 3544 | ++__first; |
| 3545 | __push_loop(0, 1, __s, __mexp_begin, __mexp_end, false); |
| 3546 | } |
| 3547 | else |
| 3548 | __push_loop(0, 1, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3549 | break; |
| 3550 | case '{': |
| 3551 | { |
| 3552 | int __min; |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3553 | _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3554 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3555 | if (__temp == __first) |
| 3556 | throw regex_error(regex_constants::error_badbrace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3557 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3558 | __first = __temp; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3559 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3560 | if (__first == __last) |
| 3561 | throw regex_error(regex_constants::error_brace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3562 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3563 | switch (*__first) |
| 3564 | { |
| 3565 | case '}': |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3566 | ++__first; |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3567 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3568 | { |
| 3569 | ++__first; |
| 3570 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, false); |
| 3571 | } |
| 3572 | else |
| 3573 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3574 | break; |
| 3575 | case ',': |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3576 | ++__first; |
| 3577 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3578 | if (__first == __last) |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3579 | throw regex_error(regex_constants::error_badbrace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3580 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3581 | if (*__first == '}') |
| 3582 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3583 | ++__first; |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3584 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3585 | { |
| 3586 | ++__first; |
| 3587 | __push_nongreedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
| 3588 | } |
| 3589 | else |
| 3590 | __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3591 | } |
| 3592 | else |
| 3593 | { |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3594 | int __max = -1; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3595 | __temp = __parse_DUP_COUNT(__first, __last, __max); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3596 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3597 | if (__temp == __first) |
| 3598 | throw regex_error(regex_constants::error_brace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3599 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3600 | __first = __temp; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3601 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3602 | if (__first == __last || *__first != '}') |
| 3603 | throw regex_error(regex_constants::error_brace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3604 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3605 | ++__first; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3606 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3607 | if (__max < __min) |
| 3608 | throw regex_error(regex_constants::error_badbrace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3609 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3610 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3611 | { |
| 3612 | ++__first; |
| 3613 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, false); |
| 3614 | } |
| 3615 | else |
| 3616 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3617 | } |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3618 | break; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3619 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3620 | default: |
| 3621 | throw regex_error(regex_constants::error_badbrace); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3622 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3623 | } |
| 3624 | } |
| 3625 | break; |
| 3626 | } |
| 3627 | } |
| 3628 | return __first; |
| 3629 | } |
| 3630 | |
| 3631 | template <class _CharT, class _Traits> |
| 3632 | template <class _ForwardIterator> |
| 3633 | _ForwardIterator |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3634 | basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first, |
| 3635 | _ForwardIterator __last) |
| 3636 | { |
| 3637 | if (__first != __last && *__first == '[') |
| 3638 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3639 | ++__first; |
| 3640 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3641 | if (__first == __last) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3642 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3643 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3644 | bool __negate = false; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3645 | if (*__first == '^') |
| 3646 | { |
| 3647 | ++__first; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3648 | __negate = true; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3649 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3650 | __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate); |
| 3651 | // __ml owned by *this |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3652 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3653 | if (__first == __last) |
| 3654 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3655 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3656 | if ((__flags_ & 0x1F0) != ECMAScript && *__first == ']') |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3657 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3658 | __ml->__add_char(']'); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3659 | ++__first; |
| 3660 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3661 | __first = __parse_follow_list(__first, __last, __ml); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3662 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3663 | if (__first == __last) |
| 3664 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3665 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3666 | if (*__first == '-') |
| 3667 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3668 | __ml->__add_char('-'); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3669 | ++__first; |
| 3670 | } |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3671 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3672 | if (__first == __last || *__first != ']') |
| 3673 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3674 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3675 | ++__first; |
| 3676 | } |
| 3677 | return __first; |
| 3678 | } |
| 3679 | |
| 3680 | template <class _CharT, class _Traits> |
| 3681 | template <class _ForwardIterator> |
| 3682 | _ForwardIterator |
| 3683 | basic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3684 | _ForwardIterator __last, |
| 3685 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3686 | { |
| 3687 | if (__first != __last) |
| 3688 | { |
| 3689 | while (true) |
| 3690 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3691 | _ForwardIterator __temp = __parse_expression_term(__first, __last, |
| 3692 | __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3693 | if (__temp == __first) |
| 3694 | break; |
| 3695 | __first = __temp; |
| 3696 | } |
| 3697 | } |
| 3698 | return __first; |
| 3699 | } |
| 3700 | |
| 3701 | template <class _CharT, class _Traits> |
| 3702 | template <class _ForwardIterator> |
| 3703 | _ForwardIterator |
| 3704 | basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3705 | _ForwardIterator __last, |
| 3706 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3707 | { |
| 3708 | if (__first != __last && *__first != ']') |
| 3709 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3710 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3711 | basic_string<_CharT> __start_range; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3712 | if (__temp != __last && *__first == '[') |
| 3713 | { |
| 3714 | if (*__temp == '=') |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3715 | return __parse_equivalence_class(++__temp, __last, __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3716 | else if (*__temp == ':') |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3717 | return __parse_character_class(++__temp, __last, __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3718 | else if (*__temp == '.') |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3719 | __first = __parse_collating_symbol(++__temp, __last, __start_range); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3720 | } |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3721 | unsigned __grammar = __flags_ & 0x1F0; |
| 3722 | if (__start_range.empty()) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3723 | { |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3724 | if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') |
| 3725 | { |
| 3726 | if (__grammar == ECMAScript) |
| 3727 | __first = __parse_class_escape(++__first, __last, __start_range, __ml); |
| 3728 | else |
| 3729 | __first = __parse_awk_escape(++__first, __last, &__start_range); |
| 3730 | } |
| 3731 | else |
| 3732 | { |
| 3733 | __start_range = *__first; |
| 3734 | ++__first; |
| 3735 | } |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3736 | } |
| 3737 | if (__first != __last && *__first != ']') |
| 3738 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3739 | __temp = _VSTD::next(__first); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3740 | if (__temp != __last && *__first == '-' && *__temp != ']') |
| 3741 | { |
| 3742 | // parse a range |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3743 | basic_string<_CharT> __end_range; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3744 | __first = __temp; |
| 3745 | ++__temp; |
| 3746 | if (__temp != __last && *__first == '[' && *__temp == '.') |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3747 | __first = __parse_collating_symbol(++__temp, __last, __end_range); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3748 | else |
| 3749 | { |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3750 | if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') |
| 3751 | { |
| 3752 | if (__grammar == ECMAScript) |
| 3753 | __first = __parse_class_escape(++__first, __last, |
| 3754 | __end_range, __ml); |
| 3755 | else |
| 3756 | __first = __parse_awk_escape(++__first, __last, |
| 3757 | &__end_range); |
| 3758 | } |
| 3759 | else |
| 3760 | { |
| 3761 | __end_range = *__first; |
| 3762 | ++__first; |
| 3763 | } |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3764 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3765 | __ml->__add_range(_VSTD::move(__start_range), _VSTD::move(__end_range)); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3766 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3767 | else |
| 3768 | { |
| 3769 | if (__start_range.size() == 1) |
| 3770 | __ml->__add_char(__start_range[0]); |
| 3771 | else |
| 3772 | __ml->__add_digraph(__start_range[0], __start_range[1]); |
| 3773 | } |
| 3774 | } |
| 3775 | else |
| 3776 | { |
| 3777 | if (__start_range.size() == 1) |
| 3778 | __ml->__add_char(__start_range[0]); |
| 3779 | else |
| 3780 | __ml->__add_digraph(__start_range[0], __start_range[1]); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3781 | } |
| 3782 | } |
| 3783 | return __first; |
| 3784 | } |
| 3785 | |
| 3786 | template <class _CharT, class _Traits> |
| 3787 | template <class _ForwardIterator> |
| 3788 | _ForwardIterator |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3789 | basic_regex<_CharT, _Traits>::__parse_class_escape(_ForwardIterator __first, |
| 3790 | _ForwardIterator __last, |
| 3791 | basic_string<_CharT>& __str, |
| 3792 | __bracket_expression<_CharT, _Traits>* __ml) |
| 3793 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3794 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3795 | if (__first == __last) |
| 3796 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3797 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3798 | switch (*__first) |
| 3799 | { |
| 3800 | case 0: |
| 3801 | __str = *__first; |
| 3802 | return ++__first; |
| 3803 | case 'b': |
| 3804 | __str = _CharT(8); |
| 3805 | return ++__first; |
| 3806 | case 'd': |
| 3807 | __ml->__add_class(ctype_base::digit); |
| 3808 | return ++__first; |
| 3809 | case 'D': |
| 3810 | __ml->__add_neg_class(ctype_base::digit); |
| 3811 | return ++__first; |
| 3812 | case 's': |
| 3813 | __ml->__add_class(ctype_base::space); |
| 3814 | return ++__first; |
| 3815 | case 'S': |
| 3816 | __ml->__add_neg_class(ctype_base::space); |
| 3817 | return ++__first; |
| 3818 | case 'w': |
| 3819 | __ml->__add_class(ctype_base::alnum); |
| 3820 | __ml->__add_char('_'); |
| 3821 | return ++__first; |
| 3822 | case 'W': |
| 3823 | __ml->__add_neg_class(ctype_base::alnum); |
| 3824 | __ml->__add_neg_char('_'); |
| 3825 | return ++__first; |
| 3826 | } |
| 3827 | __first = __parse_character_escape(__first, __last, &__str); |
| 3828 | return __first; |
| 3829 | } |
| 3830 | |
| 3831 | template <class _CharT, class _Traits> |
| 3832 | template <class _ForwardIterator> |
| 3833 | _ForwardIterator |
| 3834 | basic_regex<_CharT, _Traits>::__parse_awk_escape(_ForwardIterator __first, |
| 3835 | _ForwardIterator __last, |
| 3836 | basic_string<_CharT>* __str) |
| 3837 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3838 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3839 | if (__first == __last) |
| 3840 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3841 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3842 | switch (*__first) |
| 3843 | { |
| 3844 | case '\\': |
| 3845 | case '"': |
| 3846 | case '/': |
| 3847 | if (__str) |
| 3848 | *__str = *__first; |
| 3849 | else |
| 3850 | __push_char(*__first); |
| 3851 | return ++__first; |
| 3852 | case 'a': |
| 3853 | if (__str) |
| 3854 | *__str = _CharT(7); |
| 3855 | else |
| 3856 | __push_char(_CharT(7)); |
| 3857 | return ++__first; |
| 3858 | case 'b': |
| 3859 | if (__str) |
| 3860 | *__str = _CharT(8); |
| 3861 | else |
| 3862 | __push_char(_CharT(8)); |
| 3863 | return ++__first; |
| 3864 | case 'f': |
| 3865 | if (__str) |
| 3866 | *__str = _CharT(0xC); |
| 3867 | else |
| 3868 | __push_char(_CharT(0xC)); |
| 3869 | return ++__first; |
| 3870 | case 'n': |
| 3871 | if (__str) |
| 3872 | *__str = _CharT(0xA); |
| 3873 | else |
| 3874 | __push_char(_CharT(0xA)); |
| 3875 | return ++__first; |
| 3876 | case 'r': |
| 3877 | if (__str) |
| 3878 | *__str = _CharT(0xD); |
| 3879 | else |
| 3880 | __push_char(_CharT(0xD)); |
| 3881 | return ++__first; |
| 3882 | case 't': |
| 3883 | if (__str) |
| 3884 | *__str = _CharT(0x9); |
| 3885 | else |
| 3886 | __push_char(_CharT(0x9)); |
| 3887 | return ++__first; |
| 3888 | case 'v': |
| 3889 | if (__str) |
| 3890 | *__str = _CharT(0xB); |
| 3891 | else |
| 3892 | __push_char(_CharT(0xB)); |
| 3893 | return ++__first; |
| 3894 | } |
| 3895 | if ('0' <= *__first && *__first <= '7') |
| 3896 | { |
| 3897 | unsigned __val = *__first - '0'; |
| 3898 | if (++__first != __last && ('0' <= *__first && *__first <= '7')) |
| 3899 | { |
| 3900 | __val = 8 * __val + *__first - '0'; |
| 3901 | if (++__first != __last && ('0' <= *__first && *__first <= '7')) |
| 3902 | __val = 8 * __val + *__first - '0'; |
| 3903 | } |
| 3904 | if (__str) |
| 3905 | *__str = _CharT(__val); |
| 3906 | else |
| 3907 | __push_char(_CharT(__val)); |
| 3908 | } |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3909 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3910 | else |
| 3911 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3912 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3913 | return __first; |
| 3914 | } |
| 3915 | |
| 3916 | template <class _CharT, class _Traits> |
| 3917 | template <class _ForwardIterator> |
| 3918 | _ForwardIterator |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3919 | basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3920 | _ForwardIterator __last, |
| 3921 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3922 | { |
| 3923 | // Found [= |
| 3924 | // This means =] must exist |
| 3925 | value_type _Equal_close[2] = {'=', ']'}; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3926 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Equal_close, |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3927 | _Equal_close+2); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3928 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3929 | if (__temp == __last) |
| 3930 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3931 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3932 | // [__first, __temp) contains all text in [= ... =] |
| 3933 | typedef typename _Traits::string_type string_type; |
| 3934 | string_type __collate_name = |
| 3935 | __traits_.lookup_collatename(__first, __temp); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3936 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3937 | if (__collate_name.empty()) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3938 | throw regex_error(regex_constants::error_collate); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3939 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3940 | string_type __equiv_name = |
| 3941 | __traits_.transform_primary(__collate_name.begin(), |
| 3942 | __collate_name.end()); |
| 3943 | if (!__equiv_name.empty()) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3944 | __ml->__add_equivalence(__equiv_name); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3945 | else |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3946 | { |
| 3947 | switch (__collate_name.size()) |
| 3948 | { |
| 3949 | case 1: |
| 3950 | __ml->__add_char(__collate_name[0]); |
| 3951 | break; |
| 3952 | case 2: |
| 3953 | __ml->__add_digraph(__collate_name[0], __collate_name[1]); |
| 3954 | break; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3955 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3956 | default: |
| 3957 | throw regex_error(regex_constants::error_collate); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3958 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3959 | } |
| 3960 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3961 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3962 | return __first; |
| 3963 | } |
| 3964 | |
| 3965 | template <class _CharT, class _Traits> |
| 3966 | template <class _ForwardIterator> |
| 3967 | _ForwardIterator |
| 3968 | basic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3969 | _ForwardIterator __last, |
| 3970 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3971 | { |
| 3972 | // Found [: |
| 3973 | // This means :] must exist |
| 3974 | value_type _Colon_close[2] = {':', ']'}; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3975 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Colon_close, |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3976 | _Colon_close+2); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3977 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3978 | if (__temp == __last) |
| 3979 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3980 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3981 | // [__first, __temp) contains all text in [: ... :] |
| 3982 | typedef typename _Traits::char_class_type char_class_type; |
| 3983 | char_class_type __class_type = |
| 3984 | __traits_.lookup_classname(__first, __temp, __flags_ & icase); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3985 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3986 | if (__class_type == 0) |
| 3987 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3988 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3989 | __ml->__add_class(__class_type); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3990 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3991 | return __first; |
| 3992 | } |
| 3993 | |
| 3994 | template <class _CharT, class _Traits> |
| 3995 | template <class _ForwardIterator> |
| 3996 | _ForwardIterator |
| 3997 | basic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3998 | _ForwardIterator __last, |
| 3999 | basic_string<_CharT>& __col_sym) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4000 | { |
| 4001 | // Found [. |
| 4002 | // This means .] must exist |
| 4003 | value_type _Dot_close[2] = {'.', ']'}; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4004 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Dot_close, |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4005 | _Dot_close+2); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4006 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4007 | if (__temp == __last) |
| 4008 | throw regex_error(regex_constants::error_brack); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4009 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4010 | // [__first, __temp) contains all text in [. ... .] |
| 4011 | typedef typename _Traits::string_type string_type; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4012 | __col_sym = __traits_.lookup_collatename(__first, __temp); |
| 4013 | switch (__col_sym.size()) |
| 4014 | { |
| 4015 | case 1: |
| 4016 | case 2: |
| 4017 | break; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4018 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4019 | default: |
| 4020 | throw regex_error(regex_constants::error_collate); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4021 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4022 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4023 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4024 | return __first; |
| 4025 | } |
| 4026 | |
| 4027 | template <class _CharT, class _Traits> |
| 4028 | template <class _ForwardIterator> |
| 4029 | _ForwardIterator |
| 4030 | basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first, |
| 4031 | _ForwardIterator __last, |
| 4032 | int& __c) |
| 4033 | { |
| 4034 | if (__first != __last && '0' <= *__first && *__first <= '9') |
| 4035 | { |
| 4036 | __c = *__first - '0'; |
| 4037 | for (++__first; __first != __last && '0' <= *__first && *__first <= '9'; |
| 4038 | ++__first) |
| 4039 | { |
| 4040 | __c *= 10; |
| 4041 | __c += *__first - '0'; |
| 4042 | } |
| 4043 | } |
| 4044 | return __first; |
| 4045 | } |
| 4046 | |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4047 | template <class _CharT, class _Traits> |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4048 | template <class _ForwardIterator> |
| 4049 | _ForwardIterator |
| 4050 | basic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first, |
| 4051 | _ForwardIterator __last) |
| 4052 | { |
| 4053 | __owns_one_state<_CharT>* __sa = __end_; |
| 4054 | _ForwardIterator __temp = __parse_alternative(__first, __last); |
| 4055 | if (__temp == __first) |
| 4056 | __push_empty(); |
| 4057 | __first = __temp; |
| 4058 | while (__first != __last && *__first == '|') |
| 4059 | { |
| 4060 | __owns_one_state<_CharT>* __sb = __end_; |
| 4061 | __temp = __parse_alternative(++__first, __last); |
| 4062 | if (__temp == __first) |
| 4063 | __push_empty(); |
| 4064 | __push_alternation(__sa, __sb); |
| 4065 | __first = __temp; |
| 4066 | } |
| 4067 | return __first; |
| 4068 | } |
| 4069 | |
| 4070 | template <class _CharT, class _Traits> |
| 4071 | template <class _ForwardIterator> |
| 4072 | _ForwardIterator |
| 4073 | basic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first, |
| 4074 | _ForwardIterator __last) |
| 4075 | { |
| 4076 | while (true) |
| 4077 | { |
| 4078 | _ForwardIterator __temp = __parse_term(__first, __last); |
| 4079 | if (__temp == __first) |
| 4080 | break; |
| 4081 | __first = __temp; |
| 4082 | } |
| 4083 | return __first; |
| 4084 | } |
| 4085 | |
| 4086 | template <class _CharT, class _Traits> |
| 4087 | template <class _ForwardIterator> |
| 4088 | _ForwardIterator |
| 4089 | basic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first, |
| 4090 | _ForwardIterator __last) |
| 4091 | { |
| 4092 | _ForwardIterator __temp = __parse_assertion(__first, __last); |
| 4093 | if (__temp == __first) |
| 4094 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4095 | __owns_one_state<_CharT>* __e = __end_; |
| 4096 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4097 | __temp = __parse_atom(__first, __last); |
| 4098 | if (__temp != __first) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4099 | __first = __parse_ERE_dupl_symbol(__temp, __last, __e, |
| 4100 | __mexp_begin+1, __marked_count_+1); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4101 | } |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4102 | else |
| 4103 | __first = __temp; |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4104 | return __first; |
| 4105 | } |
| 4106 | |
| 4107 | template <class _CharT, class _Traits> |
| 4108 | template <class _ForwardIterator> |
| 4109 | _ForwardIterator |
| 4110 | basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first, |
| 4111 | _ForwardIterator __last) |
| 4112 | { |
| 4113 | if (__first != __last) |
| 4114 | { |
| 4115 | switch (*__first) |
| 4116 | { |
| 4117 | case '^': |
| 4118 | __push_l_anchor(); |
| 4119 | ++__first; |
| 4120 | break; |
| 4121 | case '$': |
| 4122 | __push_r_anchor(); |
| 4123 | ++__first; |
| 4124 | break; |
| 4125 | case '\\': |
| 4126 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4127 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4128 | if (__temp != __last) |
| 4129 | { |
| 4130 | if (*__temp == 'b') |
| 4131 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4132 | __push_word_boundary(false); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4133 | __first = ++__temp; |
| 4134 | } |
| 4135 | else if (*__temp == 'B') |
| 4136 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4137 | __push_word_boundary(true); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4138 | __first = ++__temp; |
| 4139 | } |
| 4140 | } |
| 4141 | } |
| 4142 | break; |
| 4143 | case '(': |
| 4144 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4145 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4146 | if (__temp != __last && *__temp == '?') |
| 4147 | { |
| 4148 | if (++__temp != __last) |
| 4149 | { |
| 4150 | switch (*__temp) |
| 4151 | { |
| 4152 | case '=': |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4153 | { |
| 4154 | basic_regex __exp; |
| 4155 | __exp.__flags_ = __flags_; |
| 4156 | __temp = __exp.__parse(++__temp, __last); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4157 | __push_lookahead(_VSTD::move(__exp), false); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4158 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4159 | if (__temp == __last || *__temp != ')') |
| 4160 | throw regex_error(regex_constants::error_paren); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4161 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4162 | __first = ++__temp; |
| 4163 | } |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4164 | break; |
| 4165 | case '!': |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4166 | { |
| 4167 | basic_regex __exp; |
| 4168 | __exp.__flags_ = __flags_; |
| 4169 | __temp = __exp.__parse(++__temp, __last); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4170 | __push_lookahead(_VSTD::move(__exp), true); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4171 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4172 | if (__temp == __last || *__temp != ')') |
| 4173 | throw regex_error(regex_constants::error_paren); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4174 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4175 | __first = ++__temp; |
| 4176 | } |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4177 | break; |
| 4178 | } |
| 4179 | } |
| 4180 | } |
| 4181 | } |
| 4182 | break; |
| 4183 | } |
| 4184 | } |
| 4185 | return __first; |
| 4186 | } |
| 4187 | |
| 4188 | template <class _CharT, class _Traits> |
| 4189 | template <class _ForwardIterator> |
| 4190 | _ForwardIterator |
| 4191 | basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first, |
| 4192 | _ForwardIterator __last) |
| 4193 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4194 | if (__first != __last) |
| 4195 | { |
| 4196 | switch (*__first) |
| 4197 | { |
| 4198 | case '.': |
| 4199 | __push_match_any_but_newline(); |
| 4200 | ++__first; |
| 4201 | break; |
| 4202 | case '\\': |
| 4203 | __first = __parse_atom_escape(__first, __last); |
| 4204 | break; |
| 4205 | case '[': |
| 4206 | __first = __parse_bracket_expression(__first, __last); |
| 4207 | break; |
| 4208 | case '(': |
| 4209 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4210 | ++__first; |
| 4211 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4212 | if (__first == __last) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4213 | throw regex_error(regex_constants::error_paren); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4214 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4215 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4216 | if (__temp != __last && *__first == '?' && *__temp == ':') |
| 4217 | { |
| 4218 | ++__open_count_; |
| 4219 | __first = __parse_ecma_exp(++__temp, __last); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4220 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4221 | if (__first == __last || *__first != ')') |
| 4222 | throw regex_error(regex_constants::error_paren); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4223 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4224 | --__open_count_; |
| 4225 | ++__first; |
| 4226 | } |
| 4227 | else |
| 4228 | { |
| 4229 | __push_begin_marked_subexpression(); |
| 4230 | unsigned __temp_count = __marked_count_; |
| 4231 | ++__open_count_; |
| 4232 | __first = __parse_ecma_exp(__first, __last); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4233 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4234 | if (__first == __last || *__first != ')') |
| 4235 | throw regex_error(regex_constants::error_paren); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4236 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4237 | __push_end_marked_subexpression(__temp_count); |
| 4238 | --__open_count_; |
| 4239 | ++__first; |
| 4240 | } |
| 4241 | } |
| 4242 | break; |
| 4243 | default: |
| 4244 | __first = __parse_pattern_character(__first, __last); |
| 4245 | break; |
| 4246 | } |
| 4247 | } |
| 4248 | return __first; |
| 4249 | } |
| 4250 | |
| 4251 | template <class _CharT, class _Traits> |
| 4252 | template <class _ForwardIterator> |
| 4253 | _ForwardIterator |
| 4254 | basic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first, |
| 4255 | _ForwardIterator __last) |
| 4256 | { |
| 4257 | if (__first != __last && *__first == '\\') |
| 4258 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4259 | _ForwardIterator __t1 = _VSTD::next(__first); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4260 | _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last); |
| 4261 | if (__t2 != __t1) |
| 4262 | __first = __t2; |
| 4263 | else |
| 4264 | { |
| 4265 | __t2 = __parse_character_class_escape(__t1, __last); |
| 4266 | if (__t2 != __t1) |
| 4267 | __first = __t2; |
| 4268 | else |
| 4269 | { |
| 4270 | __t2 = __parse_character_escape(__t1, __last); |
| 4271 | if (__t2 != __t1) |
| 4272 | __first = __t2; |
| 4273 | } |
| 4274 | } |
| 4275 | } |
| 4276 | return __first; |
| 4277 | } |
| 4278 | |
| 4279 | template <class _CharT, class _Traits> |
| 4280 | template <class _ForwardIterator> |
| 4281 | _ForwardIterator |
| 4282 | basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first, |
| 4283 | _ForwardIterator __last) |
| 4284 | { |
| 4285 | if (__first != __last) |
| 4286 | { |
| 4287 | if (*__first == '0') |
| 4288 | { |
| 4289 | __push_char(_CharT()); |
| 4290 | ++__first; |
| 4291 | } |
| 4292 | else if ('1' <= *__first && *__first <= '9') |
| 4293 | { |
| 4294 | unsigned __v = *__first - '0'; |
| 4295 | for (++__first; '0' <= *__first && *__first <= '9'; ++__first) |
| 4296 | __v = 10 * __v + *__first - '0'; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4297 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4298 | if (__v > mark_count()) |
| 4299 | throw regex_error(regex_constants::error_backref); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4300 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4301 | __push_back_ref(__v); |
| 4302 | } |
| 4303 | } |
| 4304 | return __first; |
| 4305 | } |
| 4306 | |
| 4307 | template <class _CharT, class _Traits> |
| 4308 | template <class _ForwardIterator> |
| 4309 | _ForwardIterator |
| 4310 | basic_regex<_CharT, _Traits>::__parse_character_class_escape(_ForwardIterator __first, |
| 4311 | _ForwardIterator __last) |
| 4312 | { |
| 4313 | if (__first != __last) |
| 4314 | { |
| 4315 | __bracket_expression<_CharT, _Traits>* __ml; |
| 4316 | switch (*__first) |
| 4317 | { |
| 4318 | case 'd': |
| 4319 | __ml = __start_matching_list(false); |
| 4320 | __ml->__add_class(ctype_base::digit); |
| 4321 | ++__first; |
| 4322 | break; |
| 4323 | case 'D': |
| 4324 | __ml = __start_matching_list(true); |
| 4325 | __ml->__add_class(ctype_base::digit); |
| 4326 | ++__first; |
| 4327 | break; |
| 4328 | case 's': |
| 4329 | __ml = __start_matching_list(false); |
| 4330 | __ml->__add_class(ctype_base::space); |
| 4331 | ++__first; |
| 4332 | break; |
| 4333 | case 'S': |
| 4334 | __ml = __start_matching_list(true); |
| 4335 | __ml->__add_class(ctype_base::space); |
| 4336 | ++__first; |
| 4337 | break; |
| 4338 | case 'w': |
| 4339 | __ml = __start_matching_list(false); |
| 4340 | __ml->__add_class(ctype_base::alnum); |
| 4341 | __ml->__add_char('_'); |
| 4342 | ++__first; |
| 4343 | break; |
| 4344 | case 'W': |
| 4345 | __ml = __start_matching_list(true); |
| 4346 | __ml->__add_class(ctype_base::alnum); |
| 4347 | __ml->__add_char('_'); |
| 4348 | ++__first; |
| 4349 | break; |
| 4350 | } |
| 4351 | } |
| 4352 | return __first; |
| 4353 | } |
| 4354 | |
| 4355 | template <class _CharT, class _Traits> |
| 4356 | template <class _ForwardIterator> |
| 4357 | _ForwardIterator |
| 4358 | basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first, |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4359 | _ForwardIterator __last, |
| 4360 | basic_string<_CharT>* __str) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4361 | { |
| 4362 | if (__first != __last) |
| 4363 | { |
| 4364 | _ForwardIterator __t; |
| 4365 | unsigned __sum = 0; |
| 4366 | int __hd; |
| 4367 | switch (*__first) |
| 4368 | { |
| 4369 | case 'f': |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4370 | if (__str) |
| 4371 | *__str = _CharT(0xC); |
| 4372 | else |
| 4373 | __push_char(_CharT(0xC)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4374 | ++__first; |
| 4375 | break; |
| 4376 | case 'n': |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4377 | if (__str) |
| 4378 | *__str = _CharT(0xA); |
| 4379 | else |
| 4380 | __push_char(_CharT(0xA)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4381 | ++__first; |
| 4382 | break; |
| 4383 | case 'r': |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4384 | if (__str) |
| 4385 | *__str = _CharT(0xD); |
| 4386 | else |
| 4387 | __push_char(_CharT(0xD)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4388 | ++__first; |
| 4389 | break; |
| 4390 | case 't': |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4391 | if (__str) |
| 4392 | *__str = _CharT(0x9); |
| 4393 | else |
| 4394 | __push_char(_CharT(0x9)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4395 | ++__first; |
| 4396 | break; |
| 4397 | case 'v': |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4398 | if (__str) |
| 4399 | *__str = _CharT(0xB); |
| 4400 | else |
| 4401 | __push_char(_CharT(0xB)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4402 | ++__first; |
| 4403 | break; |
| 4404 | case 'c': |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4405 | if ((__t = _VSTD::next(__first)) != __last) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4406 | { |
| 4407 | if ('A' <= *__t <= 'Z' || 'a' <= *__t <= 'z') |
| 4408 | { |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4409 | if (__str) |
| 4410 | *__str = _CharT(*__t % 32); |
| 4411 | else |
| 4412 | __push_char(_CharT(*__t % 32)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4413 | __first = ++__t; |
| 4414 | } |
| 4415 | } |
| 4416 | break; |
| 4417 | case 'u': |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4418 | ++__first; |
| 4419 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4420 | if (__first == __last) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4421 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4422 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4423 | __hd = __traits_.value(*__first, 16); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4424 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4425 | if (__hd == -1) |
| 4426 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4427 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4428 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4429 | ++__first; |
| 4430 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4431 | if (__first == __last) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4432 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4433 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4434 | __hd = __traits_.value(*__first, 16); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4435 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4436 | if (__hd == -1) |
| 4437 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4438 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4439 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4440 | // drop through |
| 4441 | case 'x': |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4442 | ++__first; |
| 4443 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4444 | if (__first == __last) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4445 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4446 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4447 | __hd = __traits_.value(*__first, 16); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4448 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4449 | if (__hd == -1) |
| 4450 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4451 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4452 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4453 | ++__first; |
| 4454 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 4455 | if (__first == __last) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4456 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4457 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4458 | __hd = __traits_.value(*__first, 16); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4459 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4460 | if (__hd == -1) |
| 4461 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4462 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4463 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4464 | if (__str) |
| 4465 | *__str = _CharT(__sum); |
| 4466 | else |
| 4467 | __push_char(_CharT(__sum)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4468 | ++__first; |
| 4469 | break; |
| 4470 | default: |
| 4471 | if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum)) |
| 4472 | { |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4473 | if (__str) |
| 4474 | *__str = *__first; |
| 4475 | else |
| 4476 | __push_char(*__first); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4477 | ++__first; |
| 4478 | } |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4479 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4480 | else if (__str) |
| 4481 | throw regex_error(regex_constants::error_escape); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4482 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4483 | break; |
| 4484 | } |
| 4485 | } |
| 4486 | return __first; |
| 4487 | } |
| 4488 | |
| 4489 | template <class _CharT, class _Traits> |
| 4490 | template <class _ForwardIterator> |
| 4491 | _ForwardIterator |
| 4492 | basic_regex<_CharT, _Traits>::__parse_pattern_character(_ForwardIterator __first, |
| 4493 | _ForwardIterator __last) |
| 4494 | { |
| 4495 | if (__first != __last) |
| 4496 | { |
| 4497 | switch (*__first) |
| 4498 | { |
| 4499 | case '^': |
| 4500 | case '$': |
| 4501 | case '\\': |
| 4502 | case '.': |
| 4503 | case '*': |
| 4504 | case '+': |
| 4505 | case '?': |
| 4506 | case '(': |
| 4507 | case ')': |
| 4508 | case '[': |
| 4509 | case ']': |
| 4510 | case '{': |
| 4511 | case '}': |
| 4512 | case '|': |
| 4513 | break; |
| 4514 | default: |
| 4515 | __push_char(*__first); |
| 4516 | ++__first; |
| 4517 | break; |
| 4518 | } |
| 4519 | } |
| 4520 | return __first; |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4521 | } |
| 4522 | |
| 4523 | template <class _CharT, class _Traits> |
Howard Hinnant | 856846b | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4524 | template <class _ForwardIterator> |
| 4525 | _ForwardIterator |
| 4526 | basic_regex<_CharT, _Traits>::__parse_grep(_ForwardIterator __first, |
| 4527 | _ForwardIterator __last) |
| 4528 | { |
| 4529 | __owns_one_state<_CharT>* __sa = __end_; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4530 | _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | 856846b | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4531 | if (__t1 != __first) |
| 4532 | __parse_basic_reg_exp(__first, __t1); |
| 4533 | else |
| 4534 | __push_empty(); |
| 4535 | __first = __t1; |
| 4536 | if (__first != __last) |
| 4537 | ++__first; |
| 4538 | while (__first != __last) |
| 4539 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4540 | __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | 856846b | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4541 | __owns_one_state<_CharT>* __sb = __end_; |
| 4542 | if (__t1 != __first) |
| 4543 | __parse_basic_reg_exp(__first, __t1); |
| 4544 | else |
| 4545 | __push_empty(); |
| 4546 | __push_alternation(__sa, __sb); |
| 4547 | __first = __t1; |
| 4548 | if (__first != __last) |
| 4549 | ++__first; |
| 4550 | } |
| 4551 | return __first; |
| 4552 | } |
| 4553 | |
| 4554 | template <class _CharT, class _Traits> |
| 4555 | template <class _ForwardIterator> |
| 4556 | _ForwardIterator |
| 4557 | basic_regex<_CharT, _Traits>::__parse_egrep(_ForwardIterator __first, |
| 4558 | _ForwardIterator __last) |
| 4559 | { |
| 4560 | __owns_one_state<_CharT>* __sa = __end_; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4561 | _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | 856846b | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4562 | if (__t1 != __first) |
| 4563 | __parse_extended_reg_exp(__first, __t1); |
| 4564 | else |
| 4565 | __push_empty(); |
| 4566 | __first = __t1; |
| 4567 | if (__first != __last) |
| 4568 | ++__first; |
| 4569 | while (__first != __last) |
| 4570 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4571 | __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | 856846b | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4572 | __owns_one_state<_CharT>* __sb = __end_; |
| 4573 | if (__t1 != __first) |
| 4574 | __parse_extended_reg_exp(__first, __t1); |
| 4575 | else |
| 4576 | __push_empty(); |
| 4577 | __push_alternation(__sa, __sb); |
| 4578 | __first = __t1; |
| 4579 | if (__first != __last) |
| 4580 | ++__first; |
| 4581 | } |
| 4582 | return __first; |
| 4583 | } |
| 4584 | |
| 4585 | template <class _CharT, class _Traits> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4586 | void |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4587 | basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max, |
| 4588 | __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end, |
| 4589 | bool __greedy) |
| 4590 | { |
| 4591 | unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first())); |
| 4592 | __end_->first() = nullptr; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4593 | unique_ptr<__loop<_CharT> > __e2(new __loop<_CharT>(__loop_count_, |
| 4594 | __s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy, |
| 4595 | __min, __max)); |
| 4596 | __s->first() = nullptr; |
| 4597 | __e1.release(); |
| 4598 | __end_->first() = new __repeat_one_loop<_CharT>(__e2.get()); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4599 | __end_ = __e2->second(); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4600 | __s->first() = __e2.release(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4601 | ++__loop_count_; |
| 4602 | } |
| 4603 | |
| 4604 | template <class _CharT, class _Traits> |
| 4605 | void |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4606 | basic_regex<_CharT, _Traits>::__push_char(value_type __c) |
| 4607 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4608 | if (flags() & icase) |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4609 | __end_->first() = new __match_char_icase<_CharT, _Traits> |
| 4610 | (__traits_, __c, __end_->first()); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4611 | else if (flags() & collate) |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4612 | __end_->first() = new __match_char_collate<_CharT, _Traits> |
| 4613 | (__traits_, __c, __end_->first()); |
| 4614 | else |
| 4615 | __end_->first() = new __match_char<_CharT>(__c, __end_->first()); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 4616 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4617 | } |
| 4618 | |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4619 | template <class _CharT, class _Traits> |
| 4620 | void |
| 4621 | basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression() |
| 4622 | { |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 4623 | if (!(__flags_ & nosubs)) |
| 4624 | { |
| 4625 | __end_->first() = |
| 4626 | new __begin_marked_subexpression<_CharT>(++__marked_count_, |
| 4627 | __end_->first()); |
| 4628 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4629 | } |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4630 | } |
| 4631 | |
| 4632 | template <class _CharT, class _Traits> |
| 4633 | void |
| 4634 | basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub) |
| 4635 | { |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 4636 | if (!(__flags_ & nosubs)) |
| 4637 | { |
| 4638 | __end_->first() = |
| 4639 | new __end_marked_subexpression<_CharT>(__sub, __end_->first()); |
| 4640 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4641 | } |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4642 | } |
| 4643 | |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4644 | template <class _CharT, class _Traits> |
| 4645 | void |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 4646 | basic_regex<_CharT, _Traits>::__push_l_anchor() |
| 4647 | { |
| 4648 | __end_->first() = new __l_anchor<_CharT>(__end_->first()); |
| 4649 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4650 | } |
| 4651 | |
| 4652 | template <class _CharT, class _Traits> |
| 4653 | void |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4654 | basic_regex<_CharT, _Traits>::__push_r_anchor() |
| 4655 | { |
| 4656 | __end_->first() = new __r_anchor<_CharT>(__end_->first()); |
| 4657 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4658 | } |
| 4659 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4660 | template <class _CharT, class _Traits> |
| 4661 | void |
| 4662 | basic_regex<_CharT, _Traits>::__push_match_any() |
| 4663 | { |
| 4664 | __end_->first() = new __match_any<_CharT>(__end_->first()); |
| 4665 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4666 | } |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4667 | |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4668 | template <class _CharT, class _Traits> |
| 4669 | void |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4670 | basic_regex<_CharT, _Traits>::__push_match_any_but_newline() |
| 4671 | { |
| 4672 | __end_->first() = new __match_any_but_newline<_CharT>(__end_->first()); |
| 4673 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4674 | } |
| 4675 | |
| 4676 | template <class _CharT, class _Traits> |
| 4677 | void |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4678 | basic_regex<_CharT, _Traits>::__push_empty() |
| 4679 | { |
| 4680 | __end_->first() = new __empty_state<_CharT>(__end_->first()); |
| 4681 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4682 | } |
| 4683 | |
| 4684 | template <class _CharT, class _Traits> |
| 4685 | void |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4686 | basic_regex<_CharT, _Traits>::__push_word_boundary(bool __invert) |
| 4687 | { |
| 4688 | __end_->first() = new __word_boundary<_CharT, _Traits>(__traits_, __invert, |
| 4689 | __end_->first()); |
| 4690 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4691 | } |
| 4692 | |
| 4693 | template <class _CharT, class _Traits> |
| 4694 | void |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4695 | basic_regex<_CharT, _Traits>::__push_back_ref(int __i) |
| 4696 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4697 | if (flags() & icase) |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4698 | __end_->first() = new __back_ref_icase<_CharT, _Traits> |
| 4699 | (__traits_, __i, __end_->first()); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4700 | else if (flags() & collate) |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4701 | __end_->first() = new __back_ref_collate<_CharT, _Traits> |
| 4702 | (__traits_, __i, __end_->first()); |
| 4703 | else |
| 4704 | __end_->first() = new __back_ref<_CharT>(__i, __end_->first()); |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4705 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4706 | } |
| 4707 | |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4708 | template <class _CharT, class _Traits> |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 4709 | void |
| 4710 | basic_regex<_CharT, _Traits>::__push_alternation(__owns_one_state<_CharT>* __sa, |
| 4711 | __owns_one_state<_CharT>* __ea) |
| 4712 | { |
| 4713 | __sa->first() = new __alternate<_CharT>( |
| 4714 | static_cast<__owns_one_state<_CharT>*>(__sa->first()), |
| 4715 | static_cast<__owns_one_state<_CharT>*>(__ea->first())); |
| 4716 | __ea->first() = nullptr; |
| 4717 | __ea->first() = new __empty_state<_CharT>(__end_->first()); |
| 4718 | __end_->first() = nullptr; |
| 4719 | __end_->first() = new __empty_non_own_state<_CharT>(__ea->first()); |
| 4720 | __end_ = static_cast<__owns_one_state<_CharT>*>(__ea->first()); |
| 4721 | } |
| 4722 | |
| 4723 | template <class _CharT, class _Traits> |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4724 | __bracket_expression<_CharT, _Traits>* |
| 4725 | basic_regex<_CharT, _Traits>::__start_matching_list(bool __negate) |
| 4726 | { |
| 4727 | __bracket_expression<_CharT, _Traits>* __r = |
| 4728 | new __bracket_expression<_CharT, _Traits>(__traits_, __end_->first(), |
| 4729 | __negate, __flags_ & icase, |
| 4730 | __flags_ & collate); |
| 4731 | __end_->first() = __r; |
| 4732 | __end_ = __r; |
| 4733 | return __r; |
| 4734 | } |
| 4735 | |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4736 | template <class _CharT, class _Traits> |
| 4737 | void |
| 4738 | basic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp, |
| 4739 | bool __invert) |
| 4740 | { |
| 4741 | __end_->first() = new __lookahead<_CharT, _Traits>(__exp, __invert, |
| 4742 | __end_->first()); |
| 4743 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4744 | } |
| 4745 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 4746 | typedef basic_regex<char> regex; |
| 4747 | typedef basic_regex<wchar_t> wregex; |
| 4748 | |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4749 | // sub_match |
| 4750 | |
| 4751 | template <class _BidirectionalIterator> |
Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame^] | 4752 | class _LIBCPP_TYPE_VIS sub_match |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4753 | : public pair<_BidirectionalIterator, _BidirectionalIterator> |
| 4754 | { |
| 4755 | public: |
| 4756 | typedef _BidirectionalIterator iterator; |
| 4757 | typedef typename iterator_traits<iterator>::value_type value_type; |
| 4758 | typedef typename iterator_traits<iterator>::difference_type difference_type; |
| 4759 | typedef basic_string<value_type> string_type; |
| 4760 | |
| 4761 | bool matched; |
| 4762 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4763 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 4764 | _LIBCPP_CONSTEXPR sub_match() : matched() {} |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 4765 | |
| 4766 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4767 | difference_type length() const |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4768 | {return matched ? _VSTD::distance(this->first, this->second) : 0;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4769 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4770 | string_type str() const |
| 4771 | {return matched ? string_type(this->first, this->second) : string_type();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4772 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4773 | operator string_type() const |
| 4774 | {return str();} |
| 4775 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4776 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4777 | int compare(const sub_match& __s) const |
| 4778 | {return str().compare(__s.str());} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4779 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4780 | int compare(const string_type& __s) const |
| 4781 | {return str().compare(__s);} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4782 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4783 | int compare(const value_type* __s) const |
| 4784 | {return str().compare(__s);} |
| 4785 | }; |
| 4786 | |
| 4787 | typedef sub_match<const char*> csub_match; |
| 4788 | typedef sub_match<const wchar_t*> wcsub_match; |
| 4789 | typedef sub_match<string::const_iterator> ssub_match; |
| 4790 | typedef sub_match<wstring::const_iterator> wssub_match; |
| 4791 | |
| 4792 | template <class _BiIter> |
| 4793 | inline _LIBCPP_INLINE_VISIBILITY |
| 4794 | bool |
| 4795 | operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4796 | { |
| 4797 | return __x.compare(__y) == 0; |
| 4798 | } |
| 4799 | |
| 4800 | template <class _BiIter> |
| 4801 | inline _LIBCPP_INLINE_VISIBILITY |
| 4802 | bool |
| 4803 | operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4804 | { |
| 4805 | return !(__x == __y); |
| 4806 | } |
| 4807 | |
| 4808 | template <class _BiIter> |
| 4809 | inline _LIBCPP_INLINE_VISIBILITY |
| 4810 | bool |
| 4811 | operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4812 | { |
| 4813 | return __x.compare(__y) < 0; |
| 4814 | } |
| 4815 | |
| 4816 | template <class _BiIter> |
| 4817 | inline _LIBCPP_INLINE_VISIBILITY |
| 4818 | bool |
| 4819 | operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4820 | { |
| 4821 | return !(__y < __x); |
| 4822 | } |
| 4823 | |
| 4824 | template <class _BiIter> |
| 4825 | inline _LIBCPP_INLINE_VISIBILITY |
| 4826 | bool |
| 4827 | operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4828 | { |
| 4829 | return !(__x < __y); |
| 4830 | } |
| 4831 | |
| 4832 | template <class _BiIter> |
| 4833 | inline _LIBCPP_INLINE_VISIBILITY |
| 4834 | bool |
| 4835 | operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4836 | { |
| 4837 | return __y < __x; |
| 4838 | } |
| 4839 | |
| 4840 | template <class _BiIter, class _ST, class _SA> |
| 4841 | inline _LIBCPP_INLINE_VISIBILITY |
| 4842 | bool |
| 4843 | operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4844 | const sub_match<_BiIter>& __y) |
| 4845 | { |
| 4846 | return __y.compare(__x.c_str()) == 0; |
| 4847 | } |
| 4848 | |
| 4849 | template <class _BiIter, class _ST, class _SA> |
| 4850 | inline _LIBCPP_INLINE_VISIBILITY |
| 4851 | bool |
| 4852 | operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4853 | const sub_match<_BiIter>& __y) |
| 4854 | { |
| 4855 | return !(__x == __y); |
| 4856 | } |
| 4857 | |
| 4858 | template <class _BiIter, class _ST, class _SA> |
| 4859 | inline _LIBCPP_INLINE_VISIBILITY |
| 4860 | bool |
| 4861 | operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4862 | const sub_match<_BiIter>& __y) |
| 4863 | { |
| 4864 | return __y.compare(__x.c_str()) > 0; |
| 4865 | } |
| 4866 | |
| 4867 | template <class _BiIter, class _ST, class _SA> |
| 4868 | inline _LIBCPP_INLINE_VISIBILITY |
| 4869 | bool |
| 4870 | operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4871 | const sub_match<_BiIter>& __y) |
| 4872 | { |
| 4873 | return __y < __x; |
| 4874 | } |
| 4875 | |
| 4876 | template <class _BiIter, class _ST, class _SA> |
| 4877 | inline _LIBCPP_INLINE_VISIBILITY |
| 4878 | bool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4879 | const sub_match<_BiIter>& __y) |
| 4880 | { |
| 4881 | return !(__x < __y); |
| 4882 | } |
| 4883 | |
| 4884 | template <class _BiIter, class _ST, class _SA> |
| 4885 | inline _LIBCPP_INLINE_VISIBILITY |
| 4886 | bool |
| 4887 | operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4888 | const sub_match<_BiIter>& __y) |
| 4889 | { |
| 4890 | return !(__y < __x); |
| 4891 | } |
| 4892 | |
| 4893 | template <class _BiIter, class _ST, class _SA> |
| 4894 | inline _LIBCPP_INLINE_VISIBILITY |
| 4895 | bool |
| 4896 | operator==(const sub_match<_BiIter>& __x, |
| 4897 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4898 | { |
| 4899 | return __x.compare(__y.c_str()) == 0; |
| 4900 | } |
| 4901 | |
| 4902 | template <class _BiIter, class _ST, class _SA> |
| 4903 | inline _LIBCPP_INLINE_VISIBILITY |
| 4904 | bool |
| 4905 | operator!=(const sub_match<_BiIter>& __x, |
| 4906 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4907 | { |
| 4908 | return !(__x == __y); |
| 4909 | } |
| 4910 | |
| 4911 | template <class _BiIter, class _ST, class _SA> |
| 4912 | inline _LIBCPP_INLINE_VISIBILITY |
| 4913 | bool |
| 4914 | operator<(const sub_match<_BiIter>& __x, |
| 4915 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4916 | { |
| 4917 | return __x.compare(__y.c_str()) < 0; |
| 4918 | } |
| 4919 | |
| 4920 | template <class _BiIter, class _ST, class _SA> |
| 4921 | inline _LIBCPP_INLINE_VISIBILITY |
| 4922 | bool operator>(const sub_match<_BiIter>& __x, |
| 4923 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4924 | { |
| 4925 | return __y < __x; |
| 4926 | } |
| 4927 | |
| 4928 | template <class _BiIter, class _ST, class _SA> |
| 4929 | inline _LIBCPP_INLINE_VISIBILITY |
| 4930 | bool |
| 4931 | operator>=(const sub_match<_BiIter>& __x, |
| 4932 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4933 | { |
| 4934 | return !(__x < __y); |
| 4935 | } |
| 4936 | |
| 4937 | template <class _BiIter, class _ST, class _SA> |
| 4938 | inline _LIBCPP_INLINE_VISIBILITY |
| 4939 | bool |
| 4940 | operator<=(const sub_match<_BiIter>& __x, |
| 4941 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4942 | { |
| 4943 | return !(__y < __x); |
| 4944 | } |
| 4945 | |
| 4946 | template <class _BiIter> |
| 4947 | inline _LIBCPP_INLINE_VISIBILITY |
| 4948 | bool |
| 4949 | operator==(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4950 | const sub_match<_BiIter>& __y) |
| 4951 | { |
| 4952 | return __y.compare(__x) == 0; |
| 4953 | } |
| 4954 | |
| 4955 | template <class _BiIter> |
| 4956 | inline _LIBCPP_INLINE_VISIBILITY |
| 4957 | bool |
| 4958 | operator!=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4959 | const sub_match<_BiIter>& __y) |
| 4960 | { |
| 4961 | return !(__x == __y); |
| 4962 | } |
| 4963 | |
| 4964 | template <class _BiIter> |
| 4965 | inline _LIBCPP_INLINE_VISIBILITY |
| 4966 | bool |
| 4967 | operator<(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4968 | const sub_match<_BiIter>& __y) |
| 4969 | { |
| 4970 | return __y.compare(__x) > 0; |
| 4971 | } |
| 4972 | |
| 4973 | template <class _BiIter> |
| 4974 | inline _LIBCPP_INLINE_VISIBILITY |
| 4975 | bool |
| 4976 | operator>(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4977 | const sub_match<_BiIter>& __y) |
| 4978 | { |
| 4979 | return __y < __x; |
| 4980 | } |
| 4981 | |
| 4982 | template <class _BiIter> |
| 4983 | inline _LIBCPP_INLINE_VISIBILITY |
| 4984 | bool |
| 4985 | operator>=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4986 | const sub_match<_BiIter>& __y) |
| 4987 | { |
| 4988 | return !(__x < __y); |
| 4989 | } |
| 4990 | |
| 4991 | template <class _BiIter> |
| 4992 | inline _LIBCPP_INLINE_VISIBILITY |
| 4993 | bool |
| 4994 | operator<=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4995 | const sub_match<_BiIter>& __y) |
| 4996 | { |
| 4997 | return !(__y < __x); |
| 4998 | } |
| 4999 | |
| 5000 | template <class _BiIter> |
| 5001 | inline _LIBCPP_INLINE_VISIBILITY |
| 5002 | bool |
| 5003 | operator==(const sub_match<_BiIter>& __x, |
| 5004 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5005 | { |
| 5006 | return __x.compare(__y) == 0; |
| 5007 | } |
| 5008 | |
| 5009 | template <class _BiIter> |
| 5010 | inline _LIBCPP_INLINE_VISIBILITY |
| 5011 | bool |
| 5012 | operator!=(const sub_match<_BiIter>& __x, |
| 5013 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5014 | { |
| 5015 | return !(__x == __y); |
| 5016 | } |
| 5017 | |
| 5018 | template <class _BiIter> |
| 5019 | inline _LIBCPP_INLINE_VISIBILITY |
| 5020 | bool |
| 5021 | operator<(const sub_match<_BiIter>& __x, |
| 5022 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5023 | { |
| 5024 | return __x.compare(__y) < 0; |
| 5025 | } |
| 5026 | |
| 5027 | template <class _BiIter> |
| 5028 | inline _LIBCPP_INLINE_VISIBILITY |
| 5029 | bool |
| 5030 | operator>(const sub_match<_BiIter>& __x, |
| 5031 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5032 | { |
| 5033 | return __y < __x; |
| 5034 | } |
| 5035 | |
| 5036 | template <class _BiIter> |
| 5037 | inline _LIBCPP_INLINE_VISIBILITY |
| 5038 | bool |
| 5039 | operator>=(const sub_match<_BiIter>& __x, |
| 5040 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5041 | { |
| 5042 | return !(__x < __y); |
| 5043 | } |
| 5044 | |
| 5045 | template <class _BiIter> |
| 5046 | inline _LIBCPP_INLINE_VISIBILITY |
| 5047 | bool |
| 5048 | operator<=(const sub_match<_BiIter>& __x, |
| 5049 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5050 | { |
| 5051 | return !(__y < __x); |
| 5052 | } |
| 5053 | |
| 5054 | template <class _BiIter> |
| 5055 | inline _LIBCPP_INLINE_VISIBILITY |
| 5056 | bool |
| 5057 | operator==(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5058 | const sub_match<_BiIter>& __y) |
| 5059 | { |
| 5060 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5061 | return __y.compare(string_type(1, __x)) == 0; |
| 5062 | } |
| 5063 | |
| 5064 | template <class _BiIter> |
| 5065 | inline _LIBCPP_INLINE_VISIBILITY |
| 5066 | bool |
| 5067 | operator!=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5068 | const sub_match<_BiIter>& __y) |
| 5069 | { |
| 5070 | return !(__x == __y); |
| 5071 | } |
| 5072 | |
| 5073 | template <class _BiIter> |
| 5074 | inline _LIBCPP_INLINE_VISIBILITY |
| 5075 | bool |
| 5076 | operator<(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5077 | const sub_match<_BiIter>& __y) |
| 5078 | { |
| 5079 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5080 | return __y.compare(string_type(1, __x)) > 0; |
| 5081 | } |
| 5082 | |
| 5083 | template <class _BiIter> |
| 5084 | inline _LIBCPP_INLINE_VISIBILITY |
| 5085 | bool |
| 5086 | operator>(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5087 | const sub_match<_BiIter>& __y) |
| 5088 | { |
| 5089 | return __y < __x; |
| 5090 | } |
| 5091 | |
| 5092 | template <class _BiIter> |
| 5093 | inline _LIBCPP_INLINE_VISIBILITY |
| 5094 | bool |
| 5095 | operator>=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5096 | const sub_match<_BiIter>& __y) |
| 5097 | { |
| 5098 | return !(__x < __y); |
| 5099 | } |
| 5100 | |
| 5101 | template <class _BiIter> |
| 5102 | inline _LIBCPP_INLINE_VISIBILITY |
| 5103 | bool |
| 5104 | operator<=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5105 | const sub_match<_BiIter>& __y) |
| 5106 | { |
| 5107 | return !(__y < __x); |
| 5108 | } |
| 5109 | |
| 5110 | template <class _BiIter> |
| 5111 | inline _LIBCPP_INLINE_VISIBILITY |
| 5112 | bool |
| 5113 | operator==(const sub_match<_BiIter>& __x, |
| 5114 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5115 | { |
| 5116 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5117 | return __x.compare(string_type(1, __y)) == 0; |
| 5118 | } |
| 5119 | |
| 5120 | template <class _BiIter> |
| 5121 | inline _LIBCPP_INLINE_VISIBILITY |
| 5122 | bool |
| 5123 | operator!=(const sub_match<_BiIter>& __x, |
| 5124 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5125 | { |
| 5126 | return !(__x == __y); |
| 5127 | } |
| 5128 | |
| 5129 | template <class _BiIter> |
| 5130 | inline _LIBCPP_INLINE_VISIBILITY |
| 5131 | bool |
| 5132 | operator<(const sub_match<_BiIter>& __x, |
| 5133 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5134 | { |
| 5135 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5136 | return __x.compare(string_type(1, __y)) < 0; |
| 5137 | } |
| 5138 | |
| 5139 | template <class _BiIter> |
| 5140 | inline _LIBCPP_INLINE_VISIBILITY |
| 5141 | bool |
| 5142 | operator>(const sub_match<_BiIter>& __x, |
| 5143 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5144 | { |
| 5145 | return __y < __x; |
| 5146 | } |
| 5147 | |
| 5148 | template <class _BiIter> |
| 5149 | inline _LIBCPP_INLINE_VISIBILITY |
| 5150 | bool |
| 5151 | operator>=(const sub_match<_BiIter>& __x, |
| 5152 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5153 | { |
| 5154 | return !(__x < __y); |
| 5155 | } |
| 5156 | |
| 5157 | template <class _BiIter> |
| 5158 | inline _LIBCPP_INLINE_VISIBILITY |
| 5159 | bool |
| 5160 | operator<=(const sub_match<_BiIter>& __x, |
| 5161 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5162 | { |
| 5163 | return !(__y < __x); |
| 5164 | } |
| 5165 | |
| 5166 | template <class _CharT, class _ST, class _BiIter> |
| 5167 | inline _LIBCPP_INLINE_VISIBILITY |
| 5168 | basic_ostream<_CharT, _ST>& |
| 5169 | operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m) |
| 5170 | { |
| 5171 | return __os << __m.str(); |
| 5172 | } |
| 5173 | |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5174 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame^] | 5175 | class _LIBCPP_TYPE_VIS match_results |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5176 | { |
| 5177 | public: |
| 5178 | typedef _Allocator allocator_type; |
| 5179 | typedef sub_match<_BidirectionalIterator> value_type; |
| 5180 | private: |
| 5181 | typedef vector<value_type, allocator_type> __container_type; |
| 5182 | |
| 5183 | __container_type __matches_; |
| 5184 | value_type __unmatched_; |
| 5185 | value_type __prefix_; |
| 5186 | value_type __suffix_; |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5187 | bool __ready_; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5188 | public: |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5189 | _BidirectionalIterator __position_start_; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5190 | typedef const value_type& const_reference; |
| 5191 | typedef const_reference reference; |
| 5192 | typedef typename __container_type::const_iterator const_iterator; |
| 5193 | typedef const_iterator iterator; |
| 5194 | typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; |
| 5195 | typedef typename allocator_traits<allocator_type>::size_type size_type; |
| 5196 | typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type; |
| 5197 | typedef basic_string<char_type> string_type; |
| 5198 | |
| 5199 | // construct/copy/destroy: |
| 5200 | explicit match_results(const allocator_type& __a = allocator_type()); |
| 5201 | // match_results(const match_results&) = default; |
| 5202 | // match_results& operator=(const match_results&) = default; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5203 | // match_results(match_results&& __m) = default; |
| 5204 | // match_results& operator=(match_results&& __m) = default; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5205 | // ~match_results() = default; |
| 5206 | |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5207 | _LIBCPP_INLINE_VISIBILITY |
| 5208 | bool ready() const {return __ready_;} |
| 5209 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5210 | // size: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5211 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5212 | size_type size() const {return __matches_.size();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5213 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5214 | size_type max_size() const {return __matches_.max_size();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5215 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5216 | bool empty() const {return size() == 0;} |
| 5217 | |
| 5218 | // element access: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5219 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5220 | difference_type length(size_type __sub = 0) const |
| 5221 | {return (*this)[__sub].length();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5222 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5223 | difference_type position(size_type __sub = 0) const |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5224 | {return _VSTD::distance(__position_start_, (*this)[__sub].first);} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5225 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5226 | string_type str(size_type __sub = 0) const |
| 5227 | {return (*this)[__sub].str();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5228 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5229 | const_reference operator[](size_type __n) const |
| 5230 | {return __n < __matches_.size() ? __matches_[__n] : __unmatched_;} |
| 5231 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5232 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5233 | const_reference prefix() const {return __prefix_;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5234 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5235 | const_reference suffix() const {return __suffix_;} |
| 5236 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5237 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c6fe8ca | 2011-10-08 14:36:16 +0000 | [diff] [blame] | 5238 | const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5239 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5240 | const_iterator end() const {return __matches_.end();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5241 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c6fe8ca | 2011-10-08 14:36:16 +0000 | [diff] [blame] | 5242 | const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5243 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5244 | const_iterator cend() const {return __matches_.end();} |
| 5245 | |
| 5246 | // format: |
| 5247 | template <class _OutputIter> |
| 5248 | _OutputIter |
| 5249 | format(_OutputIter __out, const char_type* __fmt_first, |
| 5250 | const char_type* __fmt_last, |
| 5251 | regex_constants::match_flag_type __flags = regex_constants::format_default) const; |
| 5252 | template <class _OutputIter, class _ST, class _SA> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5253 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5254 | _OutputIter |
| 5255 | format(_OutputIter __out, const basic_string<char_type, _ST, _SA>& __fmt, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5256 | regex_constants::match_flag_type __flags = regex_constants::format_default) const |
| 5257 | {return format(__out, __fmt.data(), __fmt.data() + __fmt.size(), __flags);} |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5258 | template <class _ST, class _SA> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5259 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5260 | basic_string<char_type, _ST, _SA> |
| 5261 | format(const basic_string<char_type, _ST, _SA>& __fmt, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5262 | regex_constants::match_flag_type __flags = regex_constants::format_default) const |
| 5263 | { |
| 5264 | basic_string<char_type, _ST, _SA> __r; |
| 5265 | format(back_inserter(__r), __fmt.data(), __fmt.data() + __fmt.size(), |
| 5266 | __flags); |
| 5267 | return __r; |
| 5268 | } |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5269 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5270 | string_type |
| 5271 | format(const char_type* __fmt, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5272 | regex_constants::match_flag_type __flags = regex_constants::format_default) const |
| 5273 | { |
| 5274 | string_type __r; |
| 5275 | format(back_inserter(__r), __fmt, |
| 5276 | __fmt + char_traits<char_type>::length(__fmt), __flags); |
| 5277 | return __r; |
| 5278 | } |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5279 | |
| 5280 | // allocator: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5281 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5282 | allocator_type get_allocator() const {return __matches_.get_allocator();} |
| 5283 | |
| 5284 | // swap: |
| 5285 | void swap(match_results& __m); |
| 5286 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5287 | template <class _Bp, class _Ap> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5288 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5289 | void __assign(_BidirectionalIterator __f, _BidirectionalIterator __l, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5290 | const match_results<_Bp, _Ap>& __m, bool __no_update_pos) |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5291 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5292 | _Bp __mf = __m.prefix().first; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5293 | __matches_.resize(__m.size()); |
| 5294 | for (size_type __i = 0; __i < __matches_.size(); ++__i) |
| 5295 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5296 | __matches_[__i].first = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].first)); |
| 5297 | __matches_[__i].second = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].second)); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5298 | __matches_[__i].matched = __m[__i].matched; |
| 5299 | } |
| 5300 | __unmatched_.first = __l; |
| 5301 | __unmatched_.second = __l; |
| 5302 | __unmatched_.matched = false; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5303 | __prefix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().first)); |
| 5304 | __prefix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().second)); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5305 | __prefix_.matched = __m.prefix().matched; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5306 | __suffix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().first)); |
| 5307 | __suffix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().second)); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5308 | __suffix_.matched = __m.suffix().matched; |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5309 | if (!__no_update_pos) |
| 5310 | __position_start_ = __prefix_.first; |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5311 | __ready_ = __m.ready(); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5312 | } |
| 5313 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5314 | private: |
| 5315 | void __init(unsigned __s, |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5316 | _BidirectionalIterator __f, _BidirectionalIterator __l, |
| 5317 | bool __no_update_pos = false); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5318 | |
| 5319 | template <class, class> friend class basic_regex; |
| 5320 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5321 | template <class _Bp, class _Ap, class _Cp, class _Tp> |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5322 | friend |
| 5323 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5324 | regex_match(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&, |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5325 | regex_constants::match_flag_type); |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 5326 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5327 | template <class _Bp, class _Ap> |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5328 | friend |
| 5329 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5330 | operator==(const match_results<_Bp, _Ap>&, const match_results<_Bp, _Ap>&); |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5331 | |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 5332 | template <class, class> friend class __lookahead; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5333 | }; |
| 5334 | |
| 5335 | template <class _BidirectionalIterator, class _Allocator> |
| 5336 | match_results<_BidirectionalIterator, _Allocator>::match_results( |
| 5337 | const allocator_type& __a) |
| 5338 | : __matches_(__a), |
| 5339 | __unmatched_(), |
| 5340 | __prefix_(), |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5341 | __suffix_(), |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5342 | __position_start_(), |
| 5343 | __ready_(false) |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5344 | { |
| 5345 | } |
| 5346 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5347 | template <class _BidirectionalIterator, class _Allocator> |
| 5348 | void |
| 5349 | match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s, |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5350 | _BidirectionalIterator __f, _BidirectionalIterator __l, |
| 5351 | bool __no_update_pos) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5352 | { |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5353 | __unmatched_.first = __l; |
| 5354 | __unmatched_.second = __l; |
| 5355 | __unmatched_.matched = false; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5356 | __matches_.assign(__s, __unmatched_); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5357 | __prefix_.first = __f; |
| 5358 | __prefix_.second = __f; |
| 5359 | __prefix_.matched = false; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5360 | __suffix_ = __unmatched_; |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5361 | if (!__no_update_pos) |
| 5362 | __position_start_ = __prefix_.first; |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5363 | __ready_ = true; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5364 | } |
| 5365 | |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5366 | template <class _BidirectionalIterator, class _Allocator> |
| 5367 | template <class _OutputIter> |
| 5368 | _OutputIter |
| 5369 | match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __out, |
| 5370 | const char_type* __fmt_first, const char_type* __fmt_last, |
| 5371 | regex_constants::match_flag_type __flags) const |
| 5372 | { |
| 5373 | if (__flags & regex_constants::format_sed) |
| 5374 | { |
| 5375 | for (; __fmt_first != __fmt_last; ++__fmt_first) |
| 5376 | { |
| 5377 | if (*__fmt_first == '&') |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5378 | __out = _VSTD::copy(__matches_[0].first, __matches_[0].second, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5379 | __out); |
| 5380 | else if (*__fmt_first == '\\' && __fmt_first + 1 != __fmt_last) |
| 5381 | { |
| 5382 | ++__fmt_first; |
| 5383 | if ('0' <= *__fmt_first && *__fmt_first <= '9') |
| 5384 | { |
| 5385 | size_t __i = *__fmt_first - '0'; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5386 | __out = _VSTD::copy(__matches_[__i].first, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5387 | __matches_[__i].second, __out); |
| 5388 | } |
| 5389 | else |
| 5390 | { |
| 5391 | *__out = *__fmt_first; |
| 5392 | ++__out; |
| 5393 | } |
| 5394 | } |
| 5395 | else |
| 5396 | { |
| 5397 | *__out = *__fmt_first; |
| 5398 | ++__out; |
| 5399 | } |
| 5400 | } |
| 5401 | } |
| 5402 | else |
| 5403 | { |
| 5404 | for (; __fmt_first != __fmt_last; ++__fmt_first) |
| 5405 | { |
| 5406 | if (*__fmt_first == '$' && __fmt_first + 1 != __fmt_last) |
| 5407 | { |
| 5408 | switch (__fmt_first[1]) |
| 5409 | { |
| 5410 | case '$': |
| 5411 | *__out = *++__fmt_first; |
| 5412 | ++__out; |
| 5413 | break; |
| 5414 | case '&': |
| 5415 | ++__fmt_first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5416 | __out = _VSTD::copy(__matches_[0].first, __matches_[0].second, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5417 | __out); |
| 5418 | break; |
| 5419 | case '`': |
| 5420 | ++__fmt_first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5421 | __out = _VSTD::copy(__prefix_.first, __prefix_.second, __out); |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5422 | break; |
| 5423 | case '\'': |
| 5424 | ++__fmt_first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5425 | __out = _VSTD::copy(__suffix_.first, __suffix_.second, __out); |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5426 | break; |
| 5427 | default: |
| 5428 | if ('0' <= __fmt_first[1] && __fmt_first[1] <= '9') |
| 5429 | { |
| 5430 | ++__fmt_first; |
| 5431 | size_t __i = *__fmt_first - '0'; |
| 5432 | if (__fmt_first + 1 != __fmt_last && |
| 5433 | '0' <= __fmt_first[1] && __fmt_first[1] <= '9') |
| 5434 | { |
| 5435 | ++__fmt_first; |
| 5436 | __i = 10 * __i + *__fmt_first - '0'; |
| 5437 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5438 | __out = _VSTD::copy(__matches_[__i].first, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5439 | __matches_[__i].second, __out); |
| 5440 | } |
| 5441 | else |
| 5442 | { |
| 5443 | *__out = *__fmt_first; |
| 5444 | ++__out; |
| 5445 | } |
| 5446 | break; |
| 5447 | } |
| 5448 | } |
| 5449 | else |
| 5450 | { |
| 5451 | *__out = *__fmt_first; |
| 5452 | ++__out; |
| 5453 | } |
| 5454 | } |
| 5455 | } |
| 5456 | return __out; |
| 5457 | } |
| 5458 | |
| 5459 | template <class _BidirectionalIterator, class _Allocator> |
| 5460 | void |
| 5461 | match_results<_BidirectionalIterator, _Allocator>::swap(match_results& __m) |
| 5462 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5463 | using _VSTD::swap; |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5464 | swap(__matches_, __m.__matches_); |
| 5465 | swap(__unmatched_, __m.__unmatched_); |
| 5466 | swap(__prefix_, __m.__prefix_); |
| 5467 | swap(__suffix_, __m.__suffix_); |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5468 | swap(__position_start_, __m.__position_start_); |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5469 | swap(__ready_, __m.__ready_); |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5470 | } |
| 5471 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5472 | typedef match_results<const char*> cmatch; |
| 5473 | typedef match_results<const wchar_t*> wcmatch; |
| 5474 | typedef match_results<string::const_iterator> smatch; |
| 5475 | typedef match_results<wstring::const_iterator> wsmatch; |
| 5476 | |
| 5477 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5478 | bool |
| 5479 | operator==(const match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5480 | const match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5481 | { |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5482 | if (__x.__ready_ != __y.__ready_) |
| 5483 | return false; |
| 5484 | if (!__x.__ready_) |
| 5485 | return true; |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5486 | return __x.__matches_ == __y.__matches_ && |
| 5487 | __x.__prefix_ == __y.__prefix_ && |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5488 | __x.__suffix_ == __y.__suffix_; |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5489 | } |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5490 | |
| 5491 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5492 | inline _LIBCPP_INLINE_VISIBILITY |
| 5493 | bool |
| 5494 | operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5495 | const match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5496 | { |
| 5497 | return !(__x == __y); |
| 5498 | } |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5499 | |
| 5500 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5501 | inline _LIBCPP_INLINE_VISIBILITY |
| 5502 | void |
| 5503 | swap(match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5504 | match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5505 | { |
| 5506 | __x.swap(__y); |
| 5507 | } |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5508 | |
| 5509 | // regex_search |
| 5510 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5511 | template <class _CharT, class _Traits> |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5512 | template <class _Allocator> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5513 | bool |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5514 | basic_regex<_CharT, _Traits>::__match_at_start_ecma( |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5515 | const _CharT* __first, const _CharT* __last, |
| 5516 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5517 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5518 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5519 | vector<__state> __states; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5520 | __node* __st = __start_.get(); |
| 5521 | if (__st) |
| 5522 | { |
| 5523 | __states.push_back(__state()); |
| 5524 | __states.back().__do_ = 0; |
| 5525 | __states.back().__first_ = __first; |
| 5526 | __states.back().__current_ = __first; |
| 5527 | __states.back().__last_ = __last; |
| 5528 | __states.back().__sub_matches_.resize(mark_count()); |
| 5529 | __states.back().__loop_data_.resize(__loop_count()); |
| 5530 | __states.back().__node_ = __st; |
| 5531 | __states.back().__flags_ = __flags; |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5532 | __states.back().__at_first_ = __at_first; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5533 | do |
| 5534 | { |
| 5535 | __state& __s = __states.back(); |
| 5536 | if (__s.__node_) |
| 5537 | __s.__node_->__exec(__s); |
| 5538 | switch (__s.__do_) |
| 5539 | { |
| 5540 | case __state::__end_state: |
| 5541 | __m.__matches_[0].first = __first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5542 | __m.__matches_[0].second = _VSTD::next(__first, __s.__current_ - __first); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5543 | __m.__matches_[0].matched = true; |
| 5544 | for (unsigned __i = 0; __i < __s.__sub_matches_.size(); ++__i) |
| 5545 | __m.__matches_[__i+1] = __s.__sub_matches_[__i]; |
| 5546 | return true; |
| 5547 | case __state::__accept_and_consume: |
| 5548 | case __state::__repeat: |
| 5549 | case __state::__accept_but_not_consume: |
| 5550 | break; |
| 5551 | case __state::__split: |
| 5552 | { |
| 5553 | __state __snext = __s; |
| 5554 | __s.__node_->__exec_split(true, __s); |
| 5555 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5556 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5557 | } |
| 5558 | break; |
| 5559 | case __state::__reject: |
| 5560 | __states.pop_back(); |
| 5561 | break; |
| 5562 | default: |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 5563 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5564 | throw regex_error(regex_constants::__re_err_unknown); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 5565 | #endif |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5566 | break; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 5567 | |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5568 | } |
| 5569 | } while (!__states.empty()); |
| 5570 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5571 | return false; |
| 5572 | } |
| 5573 | |
| 5574 | template <class _CharT, class _Traits> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5575 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5576 | bool |
| 5577 | basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs( |
| 5578 | const _CharT* __first, const _CharT* __last, |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5579 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5580 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5581 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5582 | deque<__state> __states; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5583 | ptrdiff_t __highest_j = 0; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5584 | ptrdiff_t _Np = _VSTD::distance(__first, __last); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5585 | __node* __st = __start_.get(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5586 | if (__st) |
| 5587 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5588 | __states.push_back(__state()); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5589 | __states.back().__do_ = 0; |
| 5590 | __states.back().__first_ = __first; |
| 5591 | __states.back().__current_ = __first; |
| 5592 | __states.back().__last_ = __last; |
| 5593 | __states.back().__loop_data_.resize(__loop_count()); |
| 5594 | __states.back().__node_ = __st; |
| 5595 | __states.back().__flags_ = __flags; |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5596 | __states.back().__at_first_ = __at_first; |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5597 | bool __matched = false; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5598 | do |
| 5599 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5600 | __state& __s = __states.back(); |
| 5601 | if (__s.__node_) |
| 5602 | __s.__node_->__exec(__s); |
| 5603 | switch (__s.__do_) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5604 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5605 | case __state::__end_state: |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5606 | if (!__matched || __highest_j < __s.__current_ - __s.__first_) |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5607 | __highest_j = __s.__current_ - __s.__first_; |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5608 | __matched = true; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5609 | if (__highest_j == _Np) |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5610 | __states.clear(); |
| 5611 | else |
| 5612 | __states.pop_back(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5613 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5614 | case __state::__consume_input: |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5615 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5616 | case __state::__accept_and_consume: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5617 | __states.push_front(_VSTD::move(__s)); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5618 | __states.pop_back(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5619 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5620 | case __state::__repeat: |
| 5621 | case __state::__accept_but_not_consume: |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5622 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5623 | case __state::__split: |
| 5624 | { |
| 5625 | __state __snext = __s; |
| 5626 | __s.__node_->__exec_split(true, __s); |
| 5627 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5628 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5629 | } |
| 5630 | break; |
| 5631 | case __state::__reject: |
| 5632 | __states.pop_back(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5633 | break; |
| 5634 | default: |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 5635 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5636 | throw regex_error(regex_constants::__re_err_unknown); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 5637 | #endif |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5638 | break; |
| 5639 | } |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5640 | } while (!__states.empty()); |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5641 | if (__matched) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5642 | { |
| 5643 | __m.__matches_[0].first = __first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5644 | __m.__matches_[0].second = _VSTD::next(__first, __highest_j); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5645 | __m.__matches_[0].matched = true; |
| 5646 | return true; |
| 5647 | } |
| 5648 | } |
| 5649 | return false; |
| 5650 | } |
| 5651 | |
| 5652 | template <class _CharT, class _Traits> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5653 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5654 | bool |
| 5655 | basic_regex<_CharT, _Traits>::__match_at_start_posix_subs( |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5656 | const _CharT* __first, const _CharT* __last, |
| 5657 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5658 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5659 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5660 | vector<__state> __states; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5661 | __state __best_state; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5662 | ptrdiff_t __j = 0; |
| 5663 | ptrdiff_t __highest_j = 0; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5664 | ptrdiff_t _Np = _VSTD::distance(__first, __last); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5665 | __node* __st = __start_.get(); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5666 | if (__st) |
| 5667 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5668 | __states.push_back(__state()); |
| 5669 | __states.back().__do_ = 0; |
| 5670 | __states.back().__first_ = __first; |
| 5671 | __states.back().__current_ = __first; |
| 5672 | __states.back().__last_ = __last; |
| 5673 | __states.back().__sub_matches_.resize(mark_count()); |
| 5674 | __states.back().__loop_data_.resize(__loop_count()); |
| 5675 | __states.back().__node_ = __st; |
| 5676 | __states.back().__flags_ = __flags; |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5677 | __states.back().__at_first_ = __at_first; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5678 | const _CharT* __current = __first; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5679 | bool __matched = false; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5680 | do |
| 5681 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5682 | __state& __s = __states.back(); |
| 5683 | if (__s.__node_) |
| 5684 | __s.__node_->__exec(__s); |
| 5685 | switch (__s.__do_) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5686 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5687 | case __state::__end_state: |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5688 | if (!__matched || __highest_j < __s.__current_ - __s.__first_) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5689 | { |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5690 | __highest_j = __s.__current_ - __s.__first_; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5691 | __best_state = __s; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5692 | } |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5693 | __matched = true; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5694 | if (__highest_j == _Np) |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5695 | __states.clear(); |
| 5696 | else |
| 5697 | __states.pop_back(); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5698 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5699 | case __state::__accept_and_consume: |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 5700 | __j += __s.__current_ - __current; |
| 5701 | __current = __s.__current_; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5702 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5703 | case __state::__repeat: |
| 5704 | case __state::__accept_but_not_consume: |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5705 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5706 | case __state::__split: |
| 5707 | { |
| 5708 | __state __snext = __s; |
| 5709 | __s.__node_->__exec_split(true, __s); |
| 5710 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5711 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5712 | } |
| 5713 | break; |
| 5714 | case __state::__reject: |
| 5715 | __states.pop_back(); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5716 | break; |
| 5717 | default: |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 5718 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5719 | throw regex_error(regex_constants::__re_err_unknown); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 5720 | #endif |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5721 | break; |
| 5722 | } |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5723 | } while (!__states.empty()); |
| 5724 | if (__matched) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5725 | { |
| 5726 | __m.__matches_[0].first = __first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5727 | __m.__matches_[0].second = _VSTD::next(__first, __highest_j); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5728 | __m.__matches_[0].matched = true; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5729 | for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i) |
| 5730 | __m.__matches_[__i+1] = __best_state.__sub_matches_[__i]; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5731 | return true; |
| 5732 | } |
| 5733 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5734 | return false; |
| 5735 | } |
| 5736 | |
| 5737 | template <class _CharT, class _Traits> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5738 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5739 | bool |
| 5740 | basic_regex<_CharT, _Traits>::__match_at_start( |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5741 | const _CharT* __first, const _CharT* __last, |
| 5742 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5743 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5744 | { |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5745 | if ((__flags_ & 0x1F0) == ECMAScript) |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5746 | return __match_at_start_ecma(__first, __last, __m, __flags, __at_first); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5747 | if (mark_count() == 0) |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5748 | return __match_at_start_posix_nosubs(__first, __last, __m, __flags, __at_first); |
| 5749 | return __match_at_start_posix_subs(__first, __last, __m, __flags, __at_first); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5750 | } |
| 5751 | |
| 5752 | template <class _CharT, class _Traits> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5753 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5754 | bool |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5755 | basic_regex<_CharT, _Traits>::__search( |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5756 | const _CharT* __first, const _CharT* __last, |
| 5757 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5758 | regex_constants::match_flag_type __flags) const |
| 5759 | { |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5760 | __m.__init(1 + mark_count(), __first, __last, |
| 5761 | __flags & regex_constants::__no_update_pos); |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5762 | if (__match_at_start(__first, __last, __m, __flags, true)) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5763 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5764 | __m.__prefix_.second = __m[0].first; |
| 5765 | __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; |
| 5766 | __m.__suffix_.first = __m[0].second; |
| 5767 | __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; |
| 5768 | return true; |
| 5769 | } |
Howard Hinnant | 8daa733 | 2010-07-29 01:15:27 +0000 | [diff] [blame] | 5770 | if (__first != __last && !(__flags & regex_constants::match_continuous)) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5771 | { |
Howard Hinnant | f3dcca0 | 2010-07-29 15:17:28 +0000 | [diff] [blame] | 5772 | __flags |= regex_constants::match_prev_avail; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5773 | for (++__first; __first != __last; ++__first) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5774 | { |
Howard Hinnant | f3dcca0 | 2010-07-29 15:17:28 +0000 | [diff] [blame] | 5775 | __m.__matches_.assign(__m.size(), __m.__unmatched_); |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5776 | if (__match_at_start(__first, __last, __m, __flags, false)) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5777 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5778 | __m.__prefix_.second = __m[0].first; |
| 5779 | __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; |
| 5780 | __m.__suffix_.first = __m[0].second; |
| 5781 | __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; |
| 5782 | return true; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5783 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5784 | __m.__matches_.assign(__m.size(), __m.__unmatched_); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5785 | } |
| 5786 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5787 | __m.__matches_.clear(); |
| 5788 | return false; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5789 | } |
| 5790 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5791 | template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5792 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5793 | bool |
| 5794 | regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 5795 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 5796 | const basic_regex<_CharT, _Traits>& __e, |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5797 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5798 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5799 | basic_string<_CharT> __s(__first, __last); |
| 5800 | match_results<const _CharT*> __mc; |
| 5801 | bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5802 | __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5803 | return __r; |
| 5804 | } |
| 5805 | |
| 5806 | template <class _Allocator, class _CharT, class _Traits> |
| 5807 | inline _LIBCPP_INLINE_VISIBILITY |
| 5808 | bool |
| 5809 | regex_search(const _CharT* __first, const _CharT* __last, |
| 5810 | match_results<const _CharT*, _Allocator>& __m, |
| 5811 | const basic_regex<_CharT, _Traits>& __e, |
| 5812 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5813 | { |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5814 | return __e.__search(__first, __last, __m, __flags); |
| 5815 | } |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5816 | |
| 5817 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 5818 | inline _LIBCPP_INLINE_VISIBILITY |
| 5819 | bool |
| 5820 | regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 5821 | const basic_regex<_CharT, _Traits>& __e, |
| 5822 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5823 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5824 | basic_string<_CharT> __s(__first, __last); |
| 5825 | match_results<const _CharT*> __mc; |
| 5826 | return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
| 5827 | } |
| 5828 | |
| 5829 | template <class _CharT, class _Traits> |
| 5830 | inline _LIBCPP_INLINE_VISIBILITY |
| 5831 | bool |
| 5832 | regex_search(const _CharT* __first, const _CharT* __last, |
| 5833 | const basic_regex<_CharT, _Traits>& __e, |
| 5834 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5835 | { |
| 5836 | match_results<const _CharT*> __mc; |
| 5837 | return __e.__search(__first, __last, __mc, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5838 | } |
| 5839 | |
| 5840 | template <class _CharT, class _Allocator, class _Traits> |
| 5841 | inline _LIBCPP_INLINE_VISIBILITY |
| 5842 | bool |
| 5843 | regex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, |
| 5844 | const basic_regex<_CharT, _Traits>& __e, |
| 5845 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5846 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5847 | return __e.__search(__str, __str + _Traits::length(__str), __m, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5848 | } |
| 5849 | |
| 5850 | template <class _CharT, class _Traits> |
| 5851 | inline _LIBCPP_INLINE_VISIBILITY |
| 5852 | bool |
| 5853 | regex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, |
| 5854 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5855 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5856 | match_results<const _CharT*> __m; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5857 | return _VSTD::regex_search(__str, __m, __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5858 | } |
| 5859 | |
| 5860 | template <class _ST, class _SA, class _CharT, class _Traits> |
| 5861 | inline _LIBCPP_INLINE_VISIBILITY |
| 5862 | bool |
| 5863 | regex_search(const basic_string<_CharT, _ST, _SA>& __s, |
| 5864 | const basic_regex<_CharT, _Traits>& __e, |
| 5865 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5866 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5867 | match_results<const _CharT*> __mc; |
| 5868 | return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5869 | } |
| 5870 | |
| 5871 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 5872 | inline _LIBCPP_INLINE_VISIBILITY |
| 5873 | bool |
| 5874 | regex_search(const basic_string<_CharT, _ST, _SA>& __s, |
| 5875 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 5876 | const basic_regex<_CharT, _Traits>& __e, |
| 5877 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5878 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5879 | match_results<const _CharT*> __mc; |
| 5880 | bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5881 | __m.__assign(__s.begin(), __s.end(), __mc, __flags & regex_constants::__no_update_pos); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5882 | return __r; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5883 | } |
| 5884 | |
| 5885 | // regex_match |
| 5886 | |
| 5887 | template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> |
| 5888 | bool |
| 5889 | regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 5890 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 5891 | const basic_regex<_CharT, _Traits>& __e, |
| 5892 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5893 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5894 | bool __r = _VSTD::regex_search(__first, __last, __m, __e, |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5895 | __flags | regex_constants::match_continuous); |
| 5896 | if (__r) |
| 5897 | { |
| 5898 | __r = !__m.suffix().matched; |
| 5899 | if (!__r) |
| 5900 | __m.__matches_.clear(); |
| 5901 | } |
| 5902 | return __r; |
| 5903 | } |
| 5904 | |
| 5905 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 5906 | inline _LIBCPP_INLINE_VISIBILITY |
| 5907 | bool |
| 5908 | regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 5909 | const basic_regex<_CharT, _Traits>& __e, |
| 5910 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5911 | { |
| 5912 | match_results<_BidirectionalIterator> __m; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5913 | return _VSTD::regex_match(__first, __last, __m, __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5914 | } |
| 5915 | |
| 5916 | template <class _CharT, class _Allocator, class _Traits> |
| 5917 | inline _LIBCPP_INLINE_VISIBILITY |
| 5918 | bool |
| 5919 | regex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, |
| 5920 | const basic_regex<_CharT, _Traits>& __e, |
| 5921 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5922 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5923 | return _VSTD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5924 | } |
| 5925 | |
| 5926 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 5927 | inline _LIBCPP_INLINE_VISIBILITY |
| 5928 | bool |
| 5929 | regex_match(const basic_string<_CharT, _ST, _SA>& __s, |
| 5930 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 5931 | const basic_regex<_CharT, _Traits>& __e, |
| 5932 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5933 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5934 | return _VSTD::regex_match(__s.begin(), __s.end(), __m, __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5935 | } |
| 5936 | |
| 5937 | template <class _CharT, class _Traits> |
| 5938 | inline _LIBCPP_INLINE_VISIBILITY |
| 5939 | bool |
| 5940 | regex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, |
| 5941 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5942 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5943 | return _VSTD::regex_match(__str, __str + _Traits::length(__str), __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5944 | } |
| 5945 | |
| 5946 | template <class _ST, class _SA, class _CharT, class _Traits> |
| 5947 | inline _LIBCPP_INLINE_VISIBILITY |
| 5948 | bool |
| 5949 | regex_match(const basic_string<_CharT, _ST, _SA>& __s, |
| 5950 | const basic_regex<_CharT, _Traits>& __e, |
| 5951 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5952 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5953 | return _VSTD::regex_match(__s.begin(), __s.end(), __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5954 | } |
| 5955 | |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5956 | // regex_iterator |
| 5957 | |
| 5958 | template <class _BidirectionalIterator, |
| 5959 | class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type, |
| 5960 | class _Traits = regex_traits<_CharT> > |
Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame^] | 5961 | class _LIBCPP_TYPE_VIS regex_iterator |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5962 | { |
| 5963 | public: |
| 5964 | typedef basic_regex<_CharT, _Traits> regex_type; |
| 5965 | typedef match_results<_BidirectionalIterator> value_type; |
| 5966 | typedef ptrdiff_t difference_type; |
| 5967 | typedef const value_type* pointer; |
| 5968 | typedef const value_type& reference; |
| 5969 | typedef forward_iterator_tag iterator_category; |
| 5970 | |
| 5971 | private: |
| 5972 | _BidirectionalIterator __begin_; |
| 5973 | _BidirectionalIterator __end_; |
| 5974 | const regex_type* __pregex_; |
| 5975 | regex_constants::match_flag_type __flags_; |
| 5976 | value_type __match_; |
| 5977 | |
| 5978 | public: |
| 5979 | regex_iterator(); |
| 5980 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 5981 | const regex_type& __re, |
| 5982 | regex_constants::match_flag_type __m = regex_constants::match_default); |
| 5983 | |
| 5984 | bool operator==(const regex_iterator& __x) const; |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5985 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5986 | bool operator!=(const regex_iterator& __x) const {return !(*this == __x);} |
| 5987 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5988 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5989 | reference operator*() const {return __match_;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5990 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5991 | pointer operator->() const {return &__match_;} |
| 5992 | |
| 5993 | regex_iterator& operator++(); |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5994 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5995 | regex_iterator operator++(int) |
| 5996 | { |
| 5997 | regex_iterator __t(*this); |
| 5998 | ++(*this); |
| 5999 | return __t; |
| 6000 | } |
| 6001 | }; |
| 6002 | |
| 6003 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6004 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_iterator() |
| 6005 | : __begin_(), __end_(), __pregex_(nullptr), __flags_(), __match_() |
| 6006 | { |
| 6007 | } |
| 6008 | |
| 6009 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6010 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6011 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6012 | const regex_type& __re, regex_constants::match_flag_type __m) |
| 6013 | : __begin_(__a), |
| 6014 | __end_(__b), |
| 6015 | __pregex_(&__re), |
| 6016 | __flags_(__m) |
| 6017 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6018 | _VSTD::regex_search(__begin_, __end_, __match_, *__pregex_, __flags_); |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6019 | } |
| 6020 | |
| 6021 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6022 | bool |
| 6023 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6024 | operator==(const regex_iterator& __x) const |
| 6025 | { |
| 6026 | if (__match_.empty() && __x.__match_.empty()) |
| 6027 | return true; |
| 6028 | if (__match_.empty() || __x.__match_.empty()) |
| 6029 | return false; |
| 6030 | return __begin_ == __x.__begin_ && |
| 6031 | __end_ == __x.__end_ && |
| 6032 | __pregex_ == __x.__pregex_ && |
| 6033 | __flags_ == __x.__flags_ && |
| 6034 | __match_[0] == __x.__match_[0]; |
| 6035 | } |
| 6036 | |
| 6037 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6038 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6039 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() |
| 6040 | { |
| 6041 | __flags_ |= regex_constants::__no_update_pos; |
| 6042 | _BidirectionalIterator __start = __match_[0].second; |
| 6043 | if (__match_.length() == 0) |
| 6044 | { |
| 6045 | if (__start == __end_) |
| 6046 | { |
| 6047 | __match_ = value_type(); |
| 6048 | return *this; |
| 6049 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6050 | else if (_VSTD::regex_search(__start, __end_, __match_, *__pregex_, |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6051 | __flags_ | regex_constants::match_not_null | |
| 6052 | regex_constants::match_continuous)) |
| 6053 | return *this; |
| 6054 | else |
| 6055 | ++__start; |
| 6056 | } |
| 6057 | __flags_ |= regex_constants::match_prev_avail; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6058 | if (!_VSTD::regex_search(__start, __end_, __match_, *__pregex_, __flags_)) |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6059 | __match_ = value_type(); |
| 6060 | return *this; |
| 6061 | } |
| 6062 | |
| 6063 | typedef regex_iterator<const char*> cregex_iterator; |
| 6064 | typedef regex_iterator<const wchar_t*> wcregex_iterator; |
| 6065 | typedef regex_iterator<string::const_iterator> sregex_iterator; |
| 6066 | typedef regex_iterator<wstring::const_iterator> wsregex_iterator; |
| 6067 | |
| 6068 | // regex_token_iterator |
| 6069 | |
| 6070 | template <class _BidirectionalIterator, |
| 6071 | class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type, |
| 6072 | class _Traits = regex_traits<_CharT> > |
Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame^] | 6073 | class _LIBCPP_TYPE_VIS regex_token_iterator |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6074 | { |
| 6075 | public: |
| 6076 | typedef basic_regex<_CharT, _Traits> regex_type; |
| 6077 | typedef sub_match<_BidirectionalIterator> value_type; |
| 6078 | typedef ptrdiff_t difference_type; |
| 6079 | typedef const value_type* pointer; |
| 6080 | typedef const value_type& reference; |
| 6081 | typedef forward_iterator_tag iterator_category; |
| 6082 | |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6083 | private: |
| 6084 | typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position; |
| 6085 | |
| 6086 | _Position __position_; |
| 6087 | const value_type* __result_; |
| 6088 | value_type __suffix_; |
| 6089 | ptrdiff_t _N_; |
| 6090 | vector<int> __subs_; |
| 6091 | |
| 6092 | public: |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6093 | regex_token_iterator(); |
| 6094 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6095 | const regex_type& __re, int __submatch = 0, |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6096 | regex_constants::match_flag_type __m = |
| 6097 | regex_constants::match_default); |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6098 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6099 | const regex_type& __re, const vector<int>& __submatches, |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6100 | regex_constants::match_flag_type __m = |
| 6101 | regex_constants::match_default); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6102 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6103 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6104 | const regex_type& __re, |
| 6105 | initializer_list<int> __submatches, |
| 6106 | regex_constants::match_flag_type __m = |
| 6107 | regex_constants::match_default); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6108 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6109 | template <size_t _Np> |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6110 | regex_token_iterator(_BidirectionalIterator __a, |
| 6111 | _BidirectionalIterator __b, |
| 6112 | const regex_type& __re, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6113 | const int (&__submatches)[_Np], |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6114 | regex_constants::match_flag_type __m = |
| 6115 | regex_constants::match_default); |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6116 | regex_token_iterator(const regex_token_iterator&); |
| 6117 | regex_token_iterator& operator=(const regex_token_iterator&); |
| 6118 | |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6119 | bool operator==(const regex_token_iterator& __x) const; |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6120 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6121 | bool operator!=(const regex_token_iterator& __x) const {return !(*this == __x);} |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6122 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6123 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6124 | const value_type& operator*() const {return *__result_;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6125 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6126 | const value_type* operator->() const {return __result_;} |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6127 | |
| 6128 | regex_token_iterator& operator++(); |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6129 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6130 | regex_token_iterator operator++(int) |
| 6131 | { |
| 6132 | regex_token_iterator __t(*this); |
| 6133 | ++(*this); |
| 6134 | return __t; |
| 6135 | } |
| 6136 | |
| 6137 | private: |
| 6138 | void __init(_BidirectionalIterator __a, _BidirectionalIterator __b); |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6139 | }; |
| 6140 | |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6141 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6142 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6143 | regex_token_iterator() |
| 6144 | : __result_(nullptr), |
| 6145 | __suffix_(), |
| 6146 | _N_(0) |
| 6147 | { |
| 6148 | } |
| 6149 | |
| 6150 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6151 | void |
| 6152 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6153 | __init(_BidirectionalIterator __a, _BidirectionalIterator __b) |
| 6154 | { |
| 6155 | if (__position_ != _Position()) |
| 6156 | { |
| 6157 | if (__subs_[_N_] == -1) |
| 6158 | __result_ = &__position_->prefix(); |
| 6159 | else |
| 6160 | __result_ = &(*__position_)[__subs_[_N_]]; |
| 6161 | } |
| 6162 | else if (__subs_[_N_] == -1) |
| 6163 | { |
| 6164 | __suffix_.matched = true; |
| 6165 | __suffix_.first = __a; |
| 6166 | __suffix_.second = __b; |
| 6167 | __result_ = &__suffix_; |
| 6168 | } |
| 6169 | else |
| 6170 | __result_ = nullptr; |
| 6171 | } |
| 6172 | |
| 6173 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6174 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6175 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6176 | const regex_type& __re, int __submatch, |
| 6177 | regex_constants::match_flag_type __m) |
| 6178 | : __position_(__a, __b, __re, __m), |
| 6179 | _N_(0), |
| 6180 | __subs_(1, __submatch) |
| 6181 | { |
| 6182 | __init(__a, __b); |
| 6183 | } |
| 6184 | |
| 6185 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6186 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6187 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6188 | const regex_type& __re, const vector<int>& __submatches, |
| 6189 | regex_constants::match_flag_type __m) |
| 6190 | : __position_(__a, __b, __re, __m), |
| 6191 | _N_(0), |
| 6192 | __subs_(__submatches) |
| 6193 | { |
| 6194 | __init(__a, __b); |
| 6195 | } |
| 6196 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6197 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 6198 | |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6199 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6200 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6201 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6202 | const regex_type& __re, |
| 6203 | initializer_list<int> __submatches, |
| 6204 | regex_constants::match_flag_type __m) |
| 6205 | : __position_(__a, __b, __re, __m), |
| 6206 | _N_(0), |
| 6207 | __subs_(__submatches) |
| 6208 | { |
| 6209 | __init(__a, __b); |
| 6210 | } |
| 6211 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6212 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 6213 | |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6214 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6215 | template <size_t _Np> |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6216 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6217 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6218 | const regex_type& __re, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6219 | const int (&__submatches)[_Np], |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6220 | regex_constants::match_flag_type __m) |
| 6221 | : __position_(__a, __b, __re, __m), |
| 6222 | _N_(0), |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6223 | __subs_(__submatches, __submatches + _Np) |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6224 | { |
| 6225 | __init(__a, __b); |
| 6226 | } |
| 6227 | |
| 6228 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6229 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6230 | regex_token_iterator(const regex_token_iterator& __x) |
| 6231 | : __position_(__x.__position_), |
| 6232 | __result_(__x.__result_), |
| 6233 | __suffix_(__x.__suffix_), |
| 6234 | _N_(__x._N_), |
| 6235 | __subs_(__x.__subs_) |
| 6236 | { |
| 6237 | if (__x.__result_ == &__x.__suffix_) |
| 6238 | __result_ == &__suffix_; |
| 6239 | } |
| 6240 | |
| 6241 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6242 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6243 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6244 | operator=(const regex_token_iterator& __x) |
| 6245 | { |
| 6246 | if (this != &__x) |
| 6247 | { |
| 6248 | __position_ = __x.__position_; |
| 6249 | if (__x.__result_ == &__x.__suffix_) |
| 6250 | __result_ == &__suffix_; |
| 6251 | else |
| 6252 | __result_ = __x.__result_; |
| 6253 | __suffix_ = __x.__suffix_; |
| 6254 | _N_ = __x._N_; |
| 6255 | __subs_ = __x.__subs_; |
| 6256 | } |
| 6257 | return *this; |
| 6258 | } |
| 6259 | |
| 6260 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6261 | bool |
| 6262 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6263 | operator==(const regex_token_iterator& __x) const |
| 6264 | { |
| 6265 | if (__result_ == nullptr && __x.__result_ == nullptr) |
| 6266 | return true; |
| 6267 | if (__result_ == &__suffix_ && __x.__result_ == &__x.__suffix_ && |
| 6268 | __suffix_ == __x.__suffix_) |
| 6269 | return true; |
| 6270 | if (__result_ == nullptr || __x.__result_ == nullptr) |
| 6271 | return false; |
| 6272 | if (__result_ == &__suffix_ || __x.__result_ == &__x.__suffix_) |
| 6273 | return false; |
| 6274 | return __position_ == __x.__position_ && _N_ == __x._N_ && |
| 6275 | __subs_ == __x.__subs_; |
| 6276 | } |
| 6277 | |
| 6278 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6279 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6280 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() |
| 6281 | { |
| 6282 | _Position __prev = __position_; |
| 6283 | if (__result_ == &__suffix_) |
| 6284 | __result_ = nullptr; |
| 6285 | else if (_N_ + 1 < __subs_.size()) |
| 6286 | { |
| 6287 | ++_N_; |
| 6288 | if (__subs_[_N_] == -1) |
| 6289 | __result_ = &__position_->prefix(); |
| 6290 | else |
| 6291 | __result_ = &(*__position_)[__subs_[_N_]]; |
| 6292 | } |
| 6293 | else |
| 6294 | { |
| 6295 | _N_ = 0; |
| 6296 | ++__position_; |
| 6297 | if (__position_ != _Position()) |
| 6298 | { |
| 6299 | if (__subs_[_N_] == -1) |
| 6300 | __result_ = &__position_->prefix(); |
| 6301 | else |
| 6302 | __result_ = &(*__position_)[__subs_[_N_]]; |
| 6303 | } |
| 6304 | else |
| 6305 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6306 | if (_VSTD::find(__subs_.begin(), __subs_.end(), -1) != __subs_.end() |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6307 | && __prev->suffix().length() != 0) |
| 6308 | { |
| 6309 | __suffix_.matched = true; |
| 6310 | __suffix_.first = __prev->suffix().first; |
| 6311 | __suffix_.second = __prev->suffix().second; |
| 6312 | __result_ = &__suffix_; |
| 6313 | } |
| 6314 | else |
| 6315 | __result_ = nullptr; |
| 6316 | } |
| 6317 | } |
| 6318 | return *this; |
| 6319 | } |
| 6320 | |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6321 | typedef regex_token_iterator<const char*> cregex_token_iterator; |
| 6322 | typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator; |
| 6323 | typedef regex_token_iterator<string::const_iterator> sregex_token_iterator; |
| 6324 | typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator; |
| 6325 | |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6326 | // regex_replace |
| 6327 | |
| 6328 | template <class _OutputIterator, class _BidirectionalIterator, |
| 6329 | class _Traits, class _CharT> |
| 6330 | _OutputIterator |
| 6331 | regex_replace(_OutputIterator __out, |
| 6332 | _BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6333 | const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt, |
| 6334 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6335 | { |
| 6336 | typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Iter; |
| 6337 | _Iter __i(__first, __last, __e, __flags); |
| 6338 | _Iter __eof; |
| 6339 | if (__i == __eof) |
| 6340 | { |
| 6341 | if (!(__flags & regex_constants::format_no_copy)) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6342 | __out = _VSTD::copy(__first, __last, __out); |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6343 | } |
| 6344 | else |
| 6345 | { |
| 6346 | sub_match<_BidirectionalIterator> __lm; |
| 6347 | for (size_t __len = char_traits<_CharT>::length(__fmt); __i != __eof; ++__i) |
| 6348 | { |
| 6349 | if (!(__flags & regex_constants::format_no_copy)) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6350 | __out = _VSTD::copy(__i->prefix().first, __i->prefix().second, __out); |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6351 | __out = __i->format(__out, __fmt, __fmt + __len, __flags); |
| 6352 | __lm = __i->suffix(); |
| 6353 | if (__flags & regex_constants::format_first_only) |
| 6354 | break; |
| 6355 | } |
| 6356 | if (!(__flags & regex_constants::format_no_copy)) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6357 | __out = _VSTD::copy(__lm.first, __lm.second, __out); |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6358 | } |
| 6359 | return __out; |
| 6360 | } |
| 6361 | |
| 6362 | template <class _OutputIterator, class _BidirectionalIterator, |
| 6363 | class _Traits, class _CharT, class _ST, class _SA> |
| 6364 | inline _LIBCPP_INLINE_VISIBILITY |
| 6365 | _OutputIterator |
| 6366 | regex_replace(_OutputIterator __out, |
| 6367 | _BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6368 | const basic_regex<_CharT, _Traits>& __e, |
| 6369 | const basic_string<_CharT, _ST, _SA>& __fmt, |
| 6370 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6371 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6372 | return _VSTD::regex_replace(__out, __first, __last, __e, __fmt.c_str(), __flags); |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6373 | } |
| 6374 | |
| 6375 | template <class _Traits, class _CharT, class _ST, class _SA, class _FST, |
| 6376 | class _FSA> |
| 6377 | inline _LIBCPP_INLINE_VISIBILITY |
| 6378 | basic_string<_CharT, _ST, _SA> |
| 6379 | regex_replace(const basic_string<_CharT, _ST, _SA>& __s, |
| 6380 | const basic_regex<_CharT, _Traits>& __e, |
| 6381 | const basic_string<_CharT, _FST, _FSA>& __fmt, |
| 6382 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6383 | { |
| 6384 | basic_string<_CharT, _ST, _SA> __r; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6385 | _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e, |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6386 | __fmt.c_str(), __flags); |
| 6387 | return __r; |
| 6388 | } |
| 6389 | |
| 6390 | template <class _Traits, class _CharT, class _ST, class _SA> |
| 6391 | inline _LIBCPP_INLINE_VISIBILITY |
| 6392 | basic_string<_CharT, _ST, _SA> |
| 6393 | regex_replace(const basic_string<_CharT, _ST, _SA>& __s, |
| 6394 | const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt, |
| 6395 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6396 | { |
| 6397 | basic_string<_CharT, _ST, _SA> __r; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6398 | _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e, |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6399 | __fmt, __flags); |
| 6400 | return __r; |
| 6401 | } |
| 6402 | |
| 6403 | template <class _Traits, class _CharT, class _ST, class _SA> |
| 6404 | inline _LIBCPP_INLINE_VISIBILITY |
| 6405 | basic_string<_CharT> |
| 6406 | regex_replace(const _CharT* __s, |
| 6407 | const basic_regex<_CharT, _Traits>& __e, |
| 6408 | const basic_string<_CharT, _ST, _SA>& __fmt, |
| 6409 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6410 | { |
| 6411 | basic_string<_CharT> __r; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6412 | _VSTD::regex_replace(back_inserter(__r), __s, |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6413 | __s + char_traits<_CharT>::length(__s), __e, |
| 6414 | __fmt.c_str(), __flags); |
| 6415 | return __r; |
| 6416 | } |
| 6417 | |
| 6418 | template <class _Traits, class _CharT> |
| 6419 | inline _LIBCPP_INLINE_VISIBILITY |
| 6420 | basic_string<_CharT> |
| 6421 | regex_replace(const _CharT* __s, |
| 6422 | const basic_regex<_CharT, _Traits>& __e, |
| 6423 | const _CharT* __fmt, |
| 6424 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6425 | { |
| 6426 | basic_string<_CharT> __r; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6427 | _VSTD::regex_replace(back_inserter(__r), __s, |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6428 | __s + char_traits<_CharT>::length(__s), __e, |
| 6429 | __fmt, __flags); |
| 6430 | return __r; |
| 6431 | } |
| 6432 | |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 6433 | _LIBCPP_END_NAMESPACE_STD |
| 6434 | |
| 6435 | #endif // _LIBCPP_REGEX |