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; |
Hubert Tong | b49c67f | 2016-08-02 21:34:48 +0000 | [diff] [blame^] | 130 | typedef traits traits_type; |
| 131 | typedef typename traits::string_type string_type; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 132 | typedef regex_constants::syntax_option_type flag_type; |
| 133 | typedef typename traits::locale_type locale_type; |
| 134 | |
| 135 | // constants: |
| 136 | static constexpr regex_constants::syntax_option_type icase = regex_constants::icase; |
| 137 | static constexpr regex_constants::syntax_option_type nosubs = regex_constants::nosubs; |
| 138 | static constexpr regex_constants::syntax_option_type optimize = regex_constants::optimize; |
| 139 | static constexpr regex_constants::syntax_option_type collate = regex_constants::collate; |
| 140 | static constexpr regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript; |
| 141 | static constexpr regex_constants::syntax_option_type basic = regex_constants::basic; |
| 142 | static constexpr regex_constants::syntax_option_type extended = regex_constants::extended; |
| 143 | static constexpr regex_constants::syntax_option_type awk = regex_constants::awk; |
| 144 | static constexpr regex_constants::syntax_option_type grep = regex_constants::grep; |
| 145 | static constexpr regex_constants::syntax_option_type egrep = regex_constants::egrep; |
| 146 | |
| 147 | // construct/copy/destroy: |
| 148 | basic_regex(); |
| 149 | explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript); |
| 150 | basic_regex(const charT* p, size_t len, flag_type f); |
| 151 | basic_regex(const basic_regex&); |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 152 | basic_regex(basic_regex&&) noexcept; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 153 | template <class ST, class SA> |
| 154 | explicit basic_regex(const basic_string<charT, ST, SA>& p, |
| 155 | flag_type f = regex_constants::ECMAScript); |
| 156 | template <class ForwardIterator> |
| 157 | basic_regex(ForwardIterator first, ForwardIterator last, |
| 158 | flag_type f = regex_constants::ECMAScript); |
| 159 | basic_regex(initializer_list<charT>, flag_type = regex_constants::ECMAScript); |
| 160 | |
| 161 | ~basic_regex(); |
| 162 | |
| 163 | basic_regex& operator=(const basic_regex&); |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 164 | basic_regex& operator=(basic_regex&&) noexcept; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 165 | basic_regex& operator=(const charT* ptr); |
| 166 | basic_regex& operator=(initializer_list<charT> il); |
| 167 | template <class ST, class SA> |
| 168 | basic_regex& operator=(const basic_string<charT, ST, SA>& p); |
| 169 | |
| 170 | // assign: |
| 171 | basic_regex& assign(const basic_regex& that); |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 172 | basic_regex& assign(basic_regex&& that) noexcept; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 173 | basic_regex& assign(const charT* ptr, flag_type f = regex_constants::ECMAScript); |
| 174 | basic_regex& assign(const charT* p, size_t len, flag_type f); |
| 175 | template <class string_traits, class A> |
| 176 | basic_regex& assign(const basic_string<charT, string_traits, A>& s, |
| 177 | flag_type f = regex_constants::ECMAScript); |
| 178 | template <class InputIterator> |
| 179 | basic_regex& assign(InputIterator first, InputIterator last, |
| 180 | flag_type f = regex_constants::ECMAScript); |
| 181 | basic_regex& assign(initializer_list<charT>, flag_type = regex_constants::ECMAScript); |
| 182 | |
| 183 | // const operations: |
| 184 | unsigned mark_count() const; |
| 185 | flag_type flags() const; |
| 186 | |
| 187 | // locale: |
| 188 | locale_type imbue(locale_type loc); |
| 189 | locale_type getloc() const; |
| 190 | |
| 191 | // swap: |
| 192 | void swap(basic_regex&); |
| 193 | }; |
| 194 | |
| 195 | typedef basic_regex<char> regex; |
| 196 | typedef basic_regex<wchar_t> wregex; |
| 197 | |
| 198 | template <class charT, class traits> |
| 199 | void swap(basic_regex<charT, traits>& e1, basic_regex<charT, traits>& e2); |
| 200 | |
| 201 | template <class BidirectionalIterator> |
| 202 | class sub_match |
| 203 | : public pair<BidirectionalIterator, BidirectionalIterator> |
| 204 | { |
| 205 | public: |
| 206 | typedef typename iterator_traits<BidirectionalIterator>::value_type value_type; |
| 207 | typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type; |
| 208 | typedef BidirectionalIterator iterator; |
| 209 | typedef basic_string<value_type> string_type; |
| 210 | |
| 211 | bool matched; |
| 212 | |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 213 | constexpr sub_match(); |
| 214 | |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 215 | difference_type length() const; |
| 216 | operator string_type() const; |
| 217 | string_type str() const; |
| 218 | |
| 219 | int compare(const sub_match& s) const; |
| 220 | int compare(const string_type& s) const; |
| 221 | int compare(const value_type* s) const; |
| 222 | }; |
| 223 | |
| 224 | typedef sub_match<const char*> csub_match; |
| 225 | typedef sub_match<const wchar_t*> wcsub_match; |
| 226 | typedef sub_match<string::const_iterator> ssub_match; |
| 227 | typedef sub_match<wstring::const_iterator> wssub_match; |
| 228 | |
| 229 | template <class BiIter> |
| 230 | bool |
| 231 | operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); |
| 232 | |
| 233 | template <class BiIter> |
| 234 | bool |
| 235 | operator!=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); |
| 236 | |
| 237 | template <class BiIter> |
| 238 | bool |
| 239 | operator<(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); |
| 240 | |
| 241 | template <class BiIter> |
| 242 | bool |
| 243 | operator<=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); |
| 244 | |
| 245 | template <class BiIter> |
| 246 | bool |
| 247 | operator>=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); |
| 248 | |
| 249 | template <class BiIter> |
| 250 | bool |
| 251 | operator>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); |
| 252 | |
| 253 | template <class BiIter, class ST, class SA> |
| 254 | bool |
| 255 | operator==(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 256 | const sub_match<BiIter>& rhs); |
| 257 | |
| 258 | template <class BiIter, class ST, class SA> |
| 259 | bool |
| 260 | operator!=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 261 | const sub_match<BiIter>& rhs); |
| 262 | |
| 263 | template <class BiIter, class ST, class SA> |
| 264 | bool |
| 265 | operator<(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 266 | const sub_match<BiIter>& rhs); |
| 267 | |
| 268 | template <class BiIter, class ST, class SA> |
| 269 | bool |
| 270 | operator>(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 271 | const sub_match<BiIter>& rhs); |
| 272 | |
| 273 | template <class BiIter, class ST, class SA> |
| 274 | bool operator>=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 275 | const sub_match<BiIter>& rhs); |
| 276 | |
| 277 | template <class BiIter, class ST, class SA> |
| 278 | bool |
| 279 | operator<=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 280 | const sub_match<BiIter>& rhs); |
| 281 | |
| 282 | template <class BiIter, class ST, class SA> |
| 283 | bool |
| 284 | operator==(const sub_match<BiIter>& lhs, |
| 285 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 286 | |
| 287 | template <class BiIter, class ST, class SA> |
| 288 | bool |
| 289 | operator!=(const sub_match<BiIter>& lhs, |
| 290 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 291 | |
| 292 | template <class BiIter, class ST, class SA> |
| 293 | bool |
| 294 | operator<(const sub_match<BiIter>& lhs, |
| 295 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 296 | |
| 297 | template <class BiIter, class ST, class SA> |
| 298 | bool operator>(const sub_match<BiIter>& lhs, |
| 299 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 300 | |
| 301 | template <class BiIter, class ST, class SA> |
| 302 | bool |
| 303 | operator>=(const sub_match<BiIter>& lhs, |
| 304 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 305 | |
| 306 | template <class BiIter, class ST, class SA> |
| 307 | bool |
| 308 | operator<=(const sub_match<BiIter>& lhs, |
| 309 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 310 | |
| 311 | template <class BiIter> |
| 312 | bool |
| 313 | operator==(typename iterator_traits<BiIter>::value_type const* lhs, |
| 314 | const sub_match<BiIter>& rhs); |
| 315 | |
| 316 | template <class BiIter> |
| 317 | bool |
| 318 | operator!=(typename iterator_traits<BiIter>::value_type const* lhs, |
| 319 | const sub_match<BiIter>& rhs); |
| 320 | |
| 321 | template <class BiIter> |
| 322 | bool |
| 323 | operator<(typename iterator_traits<BiIter>::value_type const* lhs, |
| 324 | const sub_match<BiIter>& rhs); |
| 325 | |
| 326 | template <class BiIter> |
| 327 | bool |
| 328 | operator>(typename iterator_traits<BiIter>::value_type const* lhs, |
| 329 | const sub_match<BiIter>& rhs); |
| 330 | |
| 331 | template <class BiIter> |
| 332 | bool |
| 333 | operator>=(typename iterator_traits<BiIter>::value_type const* lhs, |
| 334 | const sub_match<BiIter>& rhs); |
| 335 | |
| 336 | template <class BiIter> |
| 337 | bool |
| 338 | operator<=(typename iterator_traits<BiIter>::value_type const* lhs, |
| 339 | const sub_match<BiIter>& rhs); |
| 340 | |
| 341 | template <class BiIter> |
| 342 | bool |
| 343 | operator==(const sub_match<BiIter>& lhs, |
| 344 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 345 | |
| 346 | template <class BiIter> |
| 347 | bool |
| 348 | operator!=(const sub_match<BiIter>& lhs, |
| 349 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 350 | |
| 351 | template <class BiIter> |
| 352 | bool |
| 353 | operator<(const sub_match<BiIter>& lhs, |
| 354 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 355 | |
| 356 | template <class BiIter> |
| 357 | bool |
| 358 | operator>(const sub_match<BiIter>& lhs, |
| 359 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 360 | |
| 361 | template <class BiIter> |
| 362 | bool |
| 363 | operator>=(const sub_match<BiIter>& lhs, |
| 364 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 365 | |
| 366 | template <class BiIter> |
| 367 | bool |
| 368 | operator<=(const sub_match<BiIter>& lhs, |
| 369 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 370 | |
| 371 | template <class BiIter> |
| 372 | bool |
| 373 | operator==(typename iterator_traits<BiIter>::value_type const& lhs, |
| 374 | const sub_match<BiIter>& rhs); |
| 375 | |
| 376 | template <class BiIter> |
| 377 | bool |
| 378 | operator!=(typename iterator_traits<BiIter>::value_type const& lhs, |
| 379 | const sub_match<BiIter>& rhs); |
| 380 | |
| 381 | template <class BiIter> |
| 382 | bool |
| 383 | operator<(typename iterator_traits<BiIter>::value_type const& lhs, |
| 384 | const sub_match<BiIter>& rhs); |
| 385 | |
| 386 | template <class BiIter> |
| 387 | bool |
| 388 | operator>(typename iterator_traits<BiIter>::value_type const& lhs, |
| 389 | const sub_match<BiIter>& rhs); |
| 390 | |
| 391 | template <class BiIter> |
| 392 | bool |
| 393 | operator>=(typename iterator_traits<BiIter>::value_type const& lhs, |
| 394 | const sub_match<BiIter>& rhs); |
| 395 | |
| 396 | template <class BiIter> |
| 397 | bool |
| 398 | operator<=(typename iterator_traits<BiIter>::value_type const& lhs, |
| 399 | const sub_match<BiIter>& rhs); |
| 400 | |
| 401 | template <class BiIter> |
| 402 | bool |
| 403 | operator==(const sub_match<BiIter>& lhs, |
| 404 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 405 | |
| 406 | template <class BiIter> |
| 407 | bool |
| 408 | operator!=(const sub_match<BiIter>& lhs, |
| 409 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 410 | |
| 411 | template <class BiIter> |
| 412 | bool |
| 413 | operator<(const sub_match<BiIter>& lhs, |
| 414 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 415 | |
| 416 | template <class BiIter> |
| 417 | bool |
| 418 | operator>(const sub_match<BiIter>& lhs, |
| 419 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 420 | |
| 421 | template <class BiIter> |
| 422 | bool |
| 423 | operator>=(const sub_match<BiIter>& lhs, |
| 424 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 425 | |
| 426 | template <class BiIter> |
| 427 | bool |
| 428 | operator<=(const sub_match<BiIter>& lhs, |
| 429 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 430 | |
| 431 | template <class charT, class ST, class BiIter> |
| 432 | basic_ostream<charT, ST>& |
| 433 | operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m); |
| 434 | |
| 435 | template <class BidirectionalIterator, |
| 436 | class Allocator = allocator<sub_match<BidirectionalIterator>>> |
| 437 | class match_results |
| 438 | { |
| 439 | public: |
| 440 | typedef sub_match<BidirectionalIterator> value_type; |
| 441 | typedef const value_type& const_reference; |
Marshall Clow | 103af34 | 2014-02-26 01:56:31 +0000 | [diff] [blame] | 442 | typedef value_type& reference; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 443 | typedef /implementation-defined/ const_iterator; |
| 444 | typedef const_iterator iterator; |
| 445 | typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type; |
| 446 | typedef typename allocator_traits<Allocator>::size_type size_type; |
| 447 | typedef Allocator allocator_type; |
| 448 | typedef typename iterator_traits<BidirectionalIterator>::value_type char_type; |
| 449 | typedef basic_string<char_type> string_type; |
| 450 | |
| 451 | // construct/copy/destroy: |
| 452 | explicit match_results(const Allocator& a = Allocator()); |
| 453 | match_results(const match_results& m); |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 454 | match_results(match_results&& m) noexcept; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 455 | match_results& operator=(const match_results& m); |
| 456 | match_results& operator=(match_results&& m); |
| 457 | ~match_results(); |
| 458 | |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 459 | bool ready() const; |
| 460 | |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 461 | // size: |
| 462 | size_type size() const; |
| 463 | size_type max_size() const; |
| 464 | bool empty() const; |
| 465 | |
| 466 | // element access: |
| 467 | difference_type length(size_type sub = 0) const; |
| 468 | difference_type position(size_type sub = 0) const; |
| 469 | string_type str(size_type sub = 0) const; |
| 470 | const_reference operator[](size_type n) const; |
| 471 | |
| 472 | const_reference prefix() const; |
| 473 | const_reference suffix() const; |
| 474 | |
| 475 | const_iterator begin() const; |
| 476 | const_iterator end() const; |
| 477 | const_iterator cbegin() const; |
| 478 | const_iterator cend() const; |
| 479 | |
| 480 | // format: |
| 481 | template <class OutputIter> |
| 482 | OutputIter |
| 483 | format(OutputIter out, const char_type* fmt_first, |
| 484 | const char_type* fmt_last, |
| 485 | regex_constants::match_flag_type flags = regex_constants::format_default) const; |
| 486 | template <class OutputIter, class ST, class SA> |
| 487 | OutputIter |
| 488 | format(OutputIter out, const basic_string<char_type, ST, SA>& fmt, |
| 489 | regex_constants::match_flag_type flags = regex_constants::format_default) const; |
| 490 | template <class ST, class SA> |
| 491 | basic_string<char_type, ST, SA> |
| 492 | format(const basic_string<char_type, ST, SA>& fmt, |
| 493 | regex_constants::match_flag_type flags = regex_constants::format_default) const; |
| 494 | string_type |
| 495 | format(const char_type* fmt, |
| 496 | regex_constants::match_flag_type flags = regex_constants::format_default) const; |
| 497 | |
| 498 | // allocator: |
| 499 | allocator_type get_allocator() const; |
| 500 | |
| 501 | // swap: |
| 502 | void swap(match_results& that); |
| 503 | }; |
| 504 | |
| 505 | typedef match_results<const char*> cmatch; |
| 506 | typedef match_results<const wchar_t*> wcmatch; |
| 507 | typedef match_results<string::const_iterator> smatch; |
| 508 | typedef match_results<wstring::const_iterator> wsmatch; |
| 509 | |
| 510 | template <class BidirectionalIterator, class Allocator> |
| 511 | bool |
| 512 | operator==(const match_results<BidirectionalIterator, Allocator>& m1, |
| 513 | const match_results<BidirectionalIterator, Allocator>& m2); |
| 514 | |
| 515 | template <class BidirectionalIterator, class Allocator> |
| 516 | bool |
| 517 | operator!=(const match_results<BidirectionalIterator, Allocator>& m1, |
| 518 | const match_results<BidirectionalIterator, Allocator>& m2); |
| 519 | |
| 520 | template <class BidirectionalIterator, class Allocator> |
| 521 | void |
| 522 | swap(match_results<BidirectionalIterator, Allocator>& m1, |
| 523 | match_results<BidirectionalIterator, Allocator>& m2); |
| 524 | |
| 525 | template <class BidirectionalIterator, class Allocator, class charT, class traits> |
| 526 | bool |
| 527 | regex_match(BidirectionalIterator first, BidirectionalIterator last, |
| 528 | match_results<BidirectionalIterator, Allocator>& m, |
| 529 | const basic_regex<charT, traits>& e, |
| 530 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 531 | |
| 532 | template <class BidirectionalIterator, class charT, class traits> |
| 533 | bool |
| 534 | regex_match(BidirectionalIterator first, BidirectionalIterator last, |
| 535 | const basic_regex<charT, traits>& e, |
| 536 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 537 | |
| 538 | template <class charT, class Allocator, class traits> |
| 539 | bool |
| 540 | regex_match(const charT* str, match_results<const charT*, Allocator>& m, |
| 541 | const basic_regex<charT, traits>& e, |
| 542 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 543 | |
| 544 | template <class ST, class SA, class Allocator, class charT, class traits> |
| 545 | bool |
| 546 | regex_match(const basic_string<charT, ST, SA>& s, |
| 547 | match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m, |
| 548 | const basic_regex<charT, traits>& e, |
| 549 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 550 | |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 551 | template <class ST, class SA, class Allocator, class charT, class traits> |
| 552 | bool |
| 553 | regex_match(const basic_string<charT, ST, SA>&& s, |
| 554 | match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m, |
| 555 | const basic_regex<charT, traits>& e, |
| 556 | regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14 |
| 557 | |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 558 | template <class charT, class traits> |
| 559 | bool |
| 560 | regex_match(const charT* str, const basic_regex<charT, traits>& e, |
| 561 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 562 | |
| 563 | template <class ST, class SA, class charT, class traits> |
| 564 | bool |
| 565 | regex_match(const basic_string<charT, ST, SA>& s, |
| 566 | const basic_regex<charT, traits>& e, |
| 567 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 568 | |
| 569 | template <class BidirectionalIterator, class Allocator, class charT, class traits> |
| 570 | bool |
| 571 | regex_search(BidirectionalIterator first, BidirectionalIterator last, |
| 572 | match_results<BidirectionalIterator, Allocator>& m, |
| 573 | const basic_regex<charT, traits>& e, |
| 574 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 575 | |
| 576 | template <class BidirectionalIterator, class charT, class traits> |
| 577 | bool |
| 578 | regex_search(BidirectionalIterator first, BidirectionalIterator last, |
| 579 | const basic_regex<charT, traits>& e, |
| 580 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 581 | |
| 582 | template <class charT, class Allocator, class traits> |
| 583 | bool |
| 584 | regex_search(const charT* str, match_results<const charT*, Allocator>& m, |
| 585 | const basic_regex<charT, traits>& e, |
| 586 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 587 | |
| 588 | template <class charT, class traits> |
| 589 | bool |
| 590 | regex_search(const charT* str, const basic_regex<charT, traits>& e, |
| 591 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 592 | |
| 593 | template <class ST, class SA, class charT, class traits> |
| 594 | bool |
| 595 | regex_search(const basic_string<charT, ST, SA>& s, |
| 596 | const basic_regex<charT, traits>& e, |
| 597 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 598 | |
| 599 | template <class ST, class SA, class Allocator, class charT, class traits> |
| 600 | bool |
| 601 | regex_search(const basic_string<charT, ST, SA>& s, |
| 602 | match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m, |
| 603 | const basic_regex<charT, traits>& e, |
| 604 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 605 | |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 606 | template <class ST, class SA, class Allocator, class charT, class traits> |
| 607 | bool |
| 608 | regex_search(const basic_string<charT, ST, SA>&& s, |
| 609 | match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m, |
| 610 | const basic_regex<charT, traits>& e, |
| 611 | regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14 |
| 612 | |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 613 | template <class OutputIterator, class BidirectionalIterator, |
| 614 | class traits, class charT, class ST, class SA> |
| 615 | OutputIterator |
| 616 | regex_replace(OutputIterator out, |
| 617 | BidirectionalIterator first, BidirectionalIterator last, |
| 618 | const basic_regex<charT, traits>& e, |
| 619 | const basic_string<charT, ST, SA>& fmt, |
| 620 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 621 | |
| 622 | template <class OutputIterator, class BidirectionalIterator, |
| 623 | class traits, class charT> |
| 624 | OutputIterator |
| 625 | regex_replace(OutputIterator out, |
| 626 | BidirectionalIterator first, BidirectionalIterator last, |
| 627 | const basic_regex<charT, traits>& e, const charT* fmt, |
| 628 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 629 | |
| 630 | template <class traits, class charT, class ST, class SA, class FST, class FSA>> |
| 631 | basic_string<charT, ST, SA> |
| 632 | regex_replace(const basic_string<charT, ST, SA>& s, |
| 633 | const basic_regex<charT, traits>& e, |
| 634 | const basic_string<charT, FST, FSA>& fmt, |
| 635 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 636 | |
| 637 | template <class traits, class charT, class ST, class SA> |
| 638 | basic_string<charT, ST, SA> |
| 639 | regex_replace(const basic_string<charT, ST, SA>& s, |
| 640 | const basic_regex<charT, traits>& e, const charT* fmt, |
| 641 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 642 | |
| 643 | template <class traits, class charT, class ST, class SA> |
| 644 | basic_string<charT> |
| 645 | regex_replace(const charT* s, |
| 646 | const basic_regex<charT, traits>& e, |
| 647 | const basic_string<charT, ST, SA>& fmt, |
| 648 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 649 | |
| 650 | template <class traits, class charT> |
| 651 | basic_string<charT> |
| 652 | regex_replace(const charT* s, |
| 653 | const basic_regex<charT, traits>& e, |
| 654 | const charT* fmt, |
| 655 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 656 | |
| 657 | template <class BidirectionalIterator, |
| 658 | class charT = typename iterator_traits< BidirectionalIterator>::value_type, |
| 659 | class traits = regex_traits<charT>> |
| 660 | class regex_iterator |
| 661 | { |
| 662 | public: |
| 663 | typedef basic_regex<charT, traits> regex_type; |
| 664 | typedef match_results<BidirectionalIterator> value_type; |
| 665 | typedef ptrdiff_t difference_type; |
| 666 | typedef const value_type* pointer; |
| 667 | typedef const value_type& reference; |
| 668 | typedef forward_iterator_tag iterator_category; |
| 669 | |
| 670 | regex_iterator(); |
| 671 | regex_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 672 | const regex_type& re, |
| 673 | regex_constants::match_flag_type m = regex_constants::match_default); |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 674 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 675 | const regex_type&& __re, |
| 676 | regex_constants::match_flag_type __m |
| 677 | = regex_constants::match_default) = delete; // C++14 |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 678 | regex_iterator(const regex_iterator&); |
| 679 | regex_iterator& operator=(const regex_iterator&); |
| 680 | |
| 681 | bool operator==(const regex_iterator&) const; |
| 682 | bool operator!=(const regex_iterator&) const; |
| 683 | |
| 684 | const value_type& operator*() const; |
| 685 | const value_type* operator->() const; |
| 686 | |
| 687 | regex_iterator& operator++(); |
| 688 | regex_iterator operator++(int); |
| 689 | }; |
| 690 | |
| 691 | typedef regex_iterator<const char*> cregex_iterator; |
| 692 | typedef regex_iterator<const wchar_t*> wcregex_iterator; |
| 693 | typedef regex_iterator<string::const_iterator> sregex_iterator; |
| 694 | typedef regex_iterator<wstring::const_iterator> wsregex_iterator; |
| 695 | |
| 696 | template <class BidirectionalIterator, |
| 697 | class charT = typename iterator_traits< BidirectionalIterator>::value_type, |
| 698 | class traits = regex_traits<charT>> |
| 699 | class regex_token_iterator |
| 700 | { |
| 701 | public: |
| 702 | typedef basic_regex<charT, traits> regex_type; |
| 703 | typedef sub_match<BidirectionalIterator> value_type; |
| 704 | typedef ptrdiff_t difference_type; |
| 705 | typedef const value_type* pointer; |
| 706 | typedef const value_type& reference; |
| 707 | typedef forward_iterator_tag iterator_category; |
| 708 | |
| 709 | regex_token_iterator(); |
| 710 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 711 | const regex_type& re, int submatch = 0, |
| 712 | regex_constants::match_flag_type m = regex_constants::match_default); |
| 713 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 714 | const regex_type&& re, int submatch = 0, |
| 715 | regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14 |
| 716 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 717 | const regex_type& re, const vector<int>& submatches, |
| 718 | regex_constants::match_flag_type m = regex_constants::match_default); |
| 719 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 720 | const regex_type&& re, const vector<int>& submatches, |
| 721 | regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14 |
| 722 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 723 | const regex_type& re, initializer_list<int> submatches, |
| 724 | regex_constants::match_flag_type m = regex_constants::match_default); |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 725 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 726 | const regex_type&& re, initializer_list<int> submatches, |
| 727 | regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14 |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 728 | template <size_t N> |
| 729 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 730 | const regex_type& re, const int (&submatches)[N], |
| 731 | regex_constants::match_flag_type m = regex_constants::match_default); |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 732 | template <size_t N> |
| 733 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 734 | const regex_type& re, const int (&submatches)[N], |
| 735 | regex_constants::match_flag_type m = regex_constants::match_default) = delete // C++14; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 736 | regex_token_iterator(const regex_token_iterator&); |
| 737 | regex_token_iterator& operator=(const regex_token_iterator&); |
| 738 | |
| 739 | bool operator==(const regex_token_iterator&) const; |
| 740 | bool operator!=(const regex_token_iterator&) const; |
| 741 | |
| 742 | const value_type& operator*() const; |
| 743 | const value_type* operator->() const; |
| 744 | |
| 745 | regex_token_iterator& operator++(); |
| 746 | regex_token_iterator operator++(int); |
| 747 | }; |
| 748 | |
| 749 | typedef regex_token_iterator<const char*> cregex_token_iterator; |
| 750 | typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator; |
| 751 | typedef regex_token_iterator<string::const_iterator> sregex_token_iterator; |
| 752 | typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator; |
| 753 | |
| 754 | } // std |
| 755 | */ |
| 756 | |
| 757 | #include <__config> |
| 758 | #include <stdexcept> |
| 759 | #include <__locale> |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 760 | #include <initializer_list> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 761 | #include <utility> |
| 762 | #include <iterator> |
| 763 | #include <string> |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 764 | #include <memory> |
| 765 | #include <vector> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 766 | #include <deque> |
Marshall Clow | fc93ce7 | 2015-08-17 21:14:16 +0000 | [diff] [blame] | 767 | #include <cassert> |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 768 | |
Howard Hinnant | 66c6f97 | 2011-11-29 16:45:27 +0000 | [diff] [blame] | 769 | #include <__undef_min_max> |
| 770 | |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 771 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 772 | #pragma GCC system_header |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 773 | #endif |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 774 | |
| 775 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 776 | |
| 777 | namespace regex_constants |
| 778 | { |
| 779 | |
| 780 | // syntax_option_type |
| 781 | |
| 782 | enum syntax_option_type |
| 783 | { |
| 784 | icase = 1 << 0, |
| 785 | nosubs = 1 << 1, |
| 786 | optimize = 1 << 2, |
| 787 | collate = 1 << 3, |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 788 | ECMAScript = 0, |
| 789 | basic = 1 << 4, |
| 790 | extended = 1 << 5, |
| 791 | awk = 1 << 6, |
| 792 | grep = 1 << 7, |
| 793 | egrep = 1 << 8 |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 794 | }; |
| 795 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 796 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 797 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 798 | syntax_option_type |
| 799 | operator~(syntax_option_type __x) |
| 800 | { |
Marshall Clow | 04bd79b | 2013-03-22 02:13:55 +0000 | [diff] [blame] | 801 | return syntax_option_type(~int(__x) & 0x1FF); |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 802 | } |
| 803 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 804 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 805 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 806 | syntax_option_type |
| 807 | operator&(syntax_option_type __x, syntax_option_type __y) |
| 808 | { |
| 809 | return syntax_option_type(int(__x) & int(__y)); |
| 810 | } |
| 811 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 812 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 813 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 814 | syntax_option_type |
| 815 | operator|(syntax_option_type __x, syntax_option_type __y) |
| 816 | { |
| 817 | return syntax_option_type(int(__x) | int(__y)); |
| 818 | } |
| 819 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 820 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 821 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 822 | syntax_option_type |
| 823 | operator^(syntax_option_type __x, syntax_option_type __y) |
| 824 | { |
| 825 | return syntax_option_type(int(__x) ^ int(__y)); |
| 826 | } |
| 827 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 828 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 829 | syntax_option_type& |
| 830 | operator&=(syntax_option_type& __x, syntax_option_type __y) |
| 831 | { |
| 832 | __x = __x & __y; |
| 833 | return __x; |
| 834 | } |
| 835 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 836 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 837 | syntax_option_type& |
| 838 | operator|=(syntax_option_type& __x, syntax_option_type __y) |
| 839 | { |
| 840 | __x = __x | __y; |
| 841 | return __x; |
| 842 | } |
| 843 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 844 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 845 | syntax_option_type& |
| 846 | operator^=(syntax_option_type& __x, syntax_option_type __y) |
| 847 | { |
| 848 | __x = __x ^ __y; |
| 849 | return __x; |
| 850 | } |
| 851 | |
| 852 | // match_flag_type |
| 853 | |
| 854 | enum match_flag_type |
| 855 | { |
| 856 | match_default = 0, |
| 857 | match_not_bol = 1 << 0, |
| 858 | match_not_eol = 1 << 1, |
| 859 | match_not_bow = 1 << 2, |
| 860 | match_not_eow = 1 << 3, |
| 861 | match_any = 1 << 4, |
| 862 | match_not_null = 1 << 5, |
| 863 | match_continuous = 1 << 6, |
| 864 | match_prev_avail = 1 << 7, |
| 865 | format_default = 0, |
| 866 | format_sed = 1 << 8, |
| 867 | format_no_copy = 1 << 9, |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 868 | format_first_only = 1 << 10, |
| 869 | __no_update_pos = 1 << 11 |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 870 | }; |
| 871 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 872 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 873 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 874 | match_flag_type |
| 875 | operator~(match_flag_type __x) |
| 876 | { |
Marshall Clow | 04bd79b | 2013-03-22 02:13:55 +0000 | [diff] [blame] | 877 | return match_flag_type(~int(__x) & 0x0FFF); |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 878 | } |
| 879 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 880 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 881 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 882 | match_flag_type |
| 883 | operator&(match_flag_type __x, match_flag_type __y) |
| 884 | { |
| 885 | return match_flag_type(int(__x) & int(__y)); |
| 886 | } |
| 887 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 888 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 889 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 890 | match_flag_type |
| 891 | operator|(match_flag_type __x, match_flag_type __y) |
| 892 | { |
| 893 | return match_flag_type(int(__x) | int(__y)); |
| 894 | } |
| 895 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 896 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 897 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 898 | match_flag_type |
| 899 | operator^(match_flag_type __x, match_flag_type __y) |
| 900 | { |
| 901 | return match_flag_type(int(__x) ^ int(__y)); |
| 902 | } |
| 903 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 904 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 905 | match_flag_type& |
| 906 | operator&=(match_flag_type& __x, match_flag_type __y) |
| 907 | { |
| 908 | __x = __x & __y; |
| 909 | return __x; |
| 910 | } |
| 911 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 912 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 913 | match_flag_type& |
| 914 | operator|=(match_flag_type& __x, match_flag_type __y) |
| 915 | { |
| 916 | __x = __x | __y; |
| 917 | return __x; |
| 918 | } |
| 919 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 920 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 921 | match_flag_type& |
| 922 | operator^=(match_flag_type& __x, match_flag_type __y) |
| 923 | { |
| 924 | __x = __x ^ __y; |
| 925 | return __x; |
| 926 | } |
| 927 | |
| 928 | enum error_type |
| 929 | { |
| 930 | error_collate = 1, |
| 931 | error_ctype, |
| 932 | error_escape, |
| 933 | error_backref, |
| 934 | error_brack, |
| 935 | error_paren, |
| 936 | error_brace, |
| 937 | error_badbrace, |
| 938 | error_range, |
| 939 | error_space, |
| 940 | error_badrepeat, |
| 941 | error_complexity, |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 942 | error_stack, |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 943 | __re_err_grammar, |
| 944 | __re_err_empty, |
| 945 | __re_err_unknown |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 946 | }; |
| 947 | |
| 948 | } // regex_constants |
| 949 | |
| 950 | class _LIBCPP_EXCEPTION_ABI regex_error |
| 951 | : public runtime_error |
| 952 | { |
| 953 | regex_constants::error_type __code_; |
| 954 | public: |
| 955 | explicit regex_error(regex_constants::error_type __ecode); |
| 956 | virtual ~regex_error() throw(); |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 957 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 958 | regex_constants::error_type code() const {return __code_;} |
| 959 | }; |
| 960 | |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 961 | template <regex_constants::error_type _Ev> |
| 962 | _LIBCPP_ALWAYS_INLINE |
| 963 | void __throw_regex_error() |
| 964 | { |
| 965 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Marshall Clow | fc93ce7 | 2015-08-17 21:14:16 +0000 | [diff] [blame] | 966 | throw regex_error(_Ev); |
| 967 | #else |
| 968 | assert(!"regex_error"); |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 969 | #endif |
| 970 | } |
| 971 | |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 972 | template <class _CharT> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 973 | struct _LIBCPP_TYPE_VIS_ONLY regex_traits |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 974 | { |
| 975 | public: |
| 976 | typedef _CharT char_type; |
| 977 | typedef basic_string<char_type> string_type; |
| 978 | typedef locale locale_type; |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 979 | typedef ctype_base::mask char_class_type; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 980 | |
Daniel Sanders | 7e87bc9 | 2016-02-17 13:16:31 +0000 | [diff] [blame] | 981 | #if defined(__mips__) && defined(__GLIBC__) |
| 982 | static const char_class_type __regex_word = static_cast<char_class_type>(_ISbit(15)); |
| 983 | #else |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 984 | static const char_class_type __regex_word = 0x80; |
Daniel Sanders | 7e87bc9 | 2016-02-17 13:16:31 +0000 | [diff] [blame] | 985 | #endif |
| 986 | |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 987 | private: |
| 988 | locale __loc_; |
| 989 | const ctype<char_type>* __ct_; |
| 990 | const collate<char_type>* __col_; |
| 991 | |
| 992 | public: |
| 993 | regex_traits(); |
| 994 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 995 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 996 | static size_t length(const char_type* __p) |
| 997 | {return char_traits<char_type>::length(__p);} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 998 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 999 | char_type translate(char_type __c) const {return __c;} |
| 1000 | char_type translate_nocase(char_type __c) const; |
| 1001 | template <class _ForwardIterator> |
| 1002 | string_type |
| 1003 | transform(_ForwardIterator __f, _ForwardIterator __l) const; |
| 1004 | template <class _ForwardIterator> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1005 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1006 | string_type |
| 1007 | transform_primary( _ForwardIterator __f, _ForwardIterator __l) const |
| 1008 | {return __transform_primary(__f, __l, char_type());} |
| 1009 | template <class _ForwardIterator> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1010 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1011 | string_type |
| 1012 | lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const |
| 1013 | {return __lookup_collatename(__f, __l, char_type());} |
| 1014 | template <class _ForwardIterator> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1015 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1016 | char_class_type |
| 1017 | lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1018 | bool __icase = false) const |
| 1019 | {return __lookup_classname(__f, __l, __icase, char_type());} |
| 1020 | bool isctype(char_type __c, char_class_type __m) const; |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1021 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1022 | int value(char_type __ch, int __radix) const |
Marshall Clow | 33ae233 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1023 | {return __regex_traits_value(__ch, __radix);} |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1024 | locale_type imbue(locale_type __l); |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1025 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1026 | locale_type getloc()const {return __loc_;} |
| 1027 | |
| 1028 | private: |
| 1029 | void __init(); |
| 1030 | |
| 1031 | template <class _ForwardIterator> |
| 1032 | string_type |
| 1033 | __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const; |
| 1034 | template <class _ForwardIterator> |
| 1035 | string_type |
| 1036 | __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; |
| 1037 | |
| 1038 | template <class _ForwardIterator> |
| 1039 | string_type |
| 1040 | __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const; |
| 1041 | template <class _ForwardIterator> |
| 1042 | string_type |
| 1043 | __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1044 | |
| 1045 | template <class _ForwardIterator> |
| 1046 | char_class_type |
| 1047 | __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
| 1048 | bool __icase, char) const; |
| 1049 | template <class _ForwardIterator> |
| 1050 | char_class_type |
| 1051 | __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
| 1052 | bool __icase, wchar_t) const; |
| 1053 | |
Marshall Clow | 33ae233 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1054 | static int __regex_traits_value(unsigned char __ch, int __radix); |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1055 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 33ae233 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1056 | int __regex_traits_value(char __ch, int __radix) const |
| 1057 | {return __regex_traits_value(static_cast<unsigned char>(__ch), __radix);} |
Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1058 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 33ae233 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1059 | int __regex_traits_value(wchar_t __ch, int __radix) const; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1060 | }; |
| 1061 | |
| 1062 | template <class _CharT> |
Howard Hinnant | 23fb972 | 2013-03-07 19:38:08 +0000 | [diff] [blame] | 1063 | const typename regex_traits<_CharT>::char_class_type |
| 1064 | regex_traits<_CharT>::__regex_word; |
| 1065 | |
| 1066 | template <class _CharT> |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1067 | regex_traits<_CharT>::regex_traits() |
| 1068 | { |
| 1069 | __init(); |
| 1070 | } |
| 1071 | |
| 1072 | template <class _CharT> |
| 1073 | typename regex_traits<_CharT>::char_type |
| 1074 | regex_traits<_CharT>::translate_nocase(char_type __c) const |
| 1075 | { |
| 1076 | return __ct_->tolower(__c); |
| 1077 | } |
| 1078 | |
| 1079 | template <class _CharT> |
| 1080 | template <class _ForwardIterator> |
| 1081 | typename regex_traits<_CharT>::string_type |
| 1082 | regex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const |
| 1083 | { |
| 1084 | string_type __s(__f, __l); |
| 1085 | return __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1086 | } |
| 1087 | |
| 1088 | template <class _CharT> |
| 1089 | void |
| 1090 | regex_traits<_CharT>::__init() |
| 1091 | { |
| 1092 | __ct_ = &use_facet<ctype<char_type> >(__loc_); |
| 1093 | __col_ = &use_facet<collate<char_type> >(__loc_); |
| 1094 | } |
| 1095 | |
| 1096 | template <class _CharT> |
| 1097 | typename regex_traits<_CharT>::locale_type |
| 1098 | regex_traits<_CharT>::imbue(locale_type __l) |
| 1099 | { |
| 1100 | locale __r = __loc_; |
| 1101 | __loc_ = __l; |
| 1102 | __init(); |
| 1103 | return __r; |
| 1104 | } |
| 1105 | |
| 1106 | // transform_primary is very FreeBSD-specific |
| 1107 | |
| 1108 | template <class _CharT> |
| 1109 | template <class _ForwardIterator> |
| 1110 | typename regex_traits<_CharT>::string_type |
| 1111 | regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, |
| 1112 | _ForwardIterator __l, char) const |
| 1113 | { |
| 1114 | const string_type __s(__f, __l); |
| 1115 | string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1116 | switch (__d.size()) |
| 1117 | { |
| 1118 | case 1: |
| 1119 | break; |
| 1120 | case 12: |
| 1121 | __d[11] = __d[3]; |
| 1122 | break; |
| 1123 | default: |
| 1124 | __d.clear(); |
| 1125 | break; |
| 1126 | } |
| 1127 | return __d; |
| 1128 | } |
| 1129 | |
| 1130 | template <class _CharT> |
| 1131 | template <class _ForwardIterator> |
| 1132 | typename regex_traits<_CharT>::string_type |
| 1133 | regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, |
| 1134 | _ForwardIterator __l, wchar_t) const |
| 1135 | { |
| 1136 | const string_type __s(__f, __l); |
| 1137 | string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1138 | switch (__d.size()) |
| 1139 | { |
| 1140 | case 1: |
| 1141 | break; |
| 1142 | case 3: |
| 1143 | __d[2] = __d[0]; |
| 1144 | break; |
| 1145 | default: |
| 1146 | __d.clear(); |
| 1147 | break; |
| 1148 | } |
| 1149 | return __d; |
| 1150 | } |
| 1151 | |
| 1152 | // lookup_collatename is very FreeBSD-specific |
| 1153 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1154 | _LIBCPP_FUNC_VIS string __get_collation_name(const char* __s); |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1155 | |
| 1156 | template <class _CharT> |
| 1157 | template <class _ForwardIterator> |
| 1158 | typename regex_traits<_CharT>::string_type |
| 1159 | regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, |
| 1160 | _ForwardIterator __l, char) const |
| 1161 | { |
| 1162 | string_type __s(__f, __l); |
| 1163 | string_type __r; |
| 1164 | if (!__s.empty()) |
| 1165 | { |
| 1166 | __r = __get_collation_name(__s.c_str()); |
| 1167 | if (__r.empty() && __s.size() <= 2) |
| 1168 | { |
| 1169 | __r = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1170 | if (__r.size() == 1 || __r.size() == 12) |
| 1171 | __r = __s; |
| 1172 | else |
| 1173 | __r.clear(); |
| 1174 | } |
| 1175 | } |
| 1176 | return __r; |
| 1177 | } |
| 1178 | |
| 1179 | template <class _CharT> |
| 1180 | template <class _ForwardIterator> |
| 1181 | typename regex_traits<_CharT>::string_type |
| 1182 | regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, |
| 1183 | _ForwardIterator __l, wchar_t) const |
| 1184 | { |
| 1185 | string_type __s(__f, __l); |
| 1186 | string __n; |
| 1187 | __n.reserve(__s.size()); |
| 1188 | for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); |
| 1189 | __i != __e; ++__i) |
| 1190 | { |
| 1191 | if (static_cast<unsigned>(*__i) >= 127) |
| 1192 | return string_type(); |
| 1193 | __n.push_back(char(*__i)); |
| 1194 | } |
| 1195 | string_type __r; |
| 1196 | if (!__s.empty()) |
| 1197 | { |
| 1198 | __n = __get_collation_name(__n.c_str()); |
| 1199 | if (!__n.empty()) |
| 1200 | __r.assign(__n.begin(), __n.end()); |
| 1201 | else if (__s.size() <= 2) |
| 1202 | { |
| 1203 | __r = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1204 | if (__r.size() == 1 || __r.size() == 3) |
| 1205 | __r = __s; |
| 1206 | else |
| 1207 | __r.clear(); |
| 1208 | } |
| 1209 | } |
| 1210 | return __r; |
| 1211 | } |
| 1212 | |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1213 | // lookup_classname |
| 1214 | |
Dan Albert | 1757386 | 2014-07-29 19:23:39 +0000 | [diff] [blame] | 1215 | regex_traits<char>::char_class_type _LIBCPP_FUNC_VIS |
| 1216 | __get_classname(const char* __s, bool __icase); |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1217 | |
| 1218 | template <class _CharT> |
| 1219 | template <class _ForwardIterator> |
| 1220 | typename regex_traits<_CharT>::char_class_type |
| 1221 | regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, |
| 1222 | _ForwardIterator __l, |
| 1223 | bool __icase, char) const |
| 1224 | { |
| 1225 | string_type __s(__f, __l); |
| 1226 | __ct_->tolower(&__s[0], &__s[0] + __s.size()); |
| 1227 | return __get_classname(__s.c_str(), __icase); |
| 1228 | } |
| 1229 | |
| 1230 | template <class _CharT> |
| 1231 | template <class _ForwardIterator> |
| 1232 | typename regex_traits<_CharT>::char_class_type |
| 1233 | regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, |
| 1234 | _ForwardIterator __l, |
| 1235 | bool __icase, wchar_t) const |
| 1236 | { |
| 1237 | string_type __s(__f, __l); |
| 1238 | __ct_->tolower(&__s[0], &__s[0] + __s.size()); |
| 1239 | string __n; |
| 1240 | __n.reserve(__s.size()); |
| 1241 | for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); |
| 1242 | __i != __e; ++__i) |
| 1243 | { |
| 1244 | if (static_cast<unsigned>(*__i) >= 127) |
| 1245 | return char_class_type(); |
| 1246 | __n.push_back(char(*__i)); |
| 1247 | } |
| 1248 | return __get_classname(__n.c_str(), __icase); |
| 1249 | } |
| 1250 | |
| 1251 | template <class _CharT> |
| 1252 | bool |
| 1253 | regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const |
| 1254 | { |
| 1255 | if (__ct_->is(__m, __c)) |
| 1256 | return true; |
| 1257 | return (__c == '_' && (__m & __regex_word)); |
| 1258 | } |
| 1259 | |
| 1260 | template <class _CharT> |
| 1261 | int |
Marshall Clow | 33ae233 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1262 | regex_traits<_CharT>::__regex_traits_value(unsigned char __ch, int __radix) |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1263 | { |
| 1264 | if ((__ch & 0xF8u) == 0x30) // '0' <= __ch && __ch <= '7' |
| 1265 | return __ch - '0'; |
| 1266 | if (__radix != 8) |
| 1267 | { |
| 1268 | if ((__ch & 0xFEu) == 0x38) // '8' <= __ch && __ch <= '9' |
| 1269 | return __ch - '0'; |
| 1270 | if (__radix == 16) |
| 1271 | { |
| 1272 | __ch |= 0x20; // tolower |
| 1273 | if ('a' <= __ch && __ch <= 'f') |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 1274 | return __ch - ('a' - 10); |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1275 | } |
| 1276 | } |
| 1277 | return -1; |
| 1278 | } |
| 1279 | |
| 1280 | template <class _CharT> |
Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1281 | inline |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1282 | int |
Marshall Clow | 33ae233 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1283 | regex_traits<_CharT>::__regex_traits_value(wchar_t __ch, int __radix) const |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1284 | { |
Marshall Clow | 33ae233 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1285 | return __regex_traits_value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix); |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1286 | } |
| 1287 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1288 | template <class _CharT> class __node; |
| 1289 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1290 | template <class _BidirectionalIterator> class _LIBCPP_TYPE_VIS_ONLY sub_match; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1291 | |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1292 | template <class _BidirectionalIterator, |
| 1293 | class _Allocator = allocator<sub_match<_BidirectionalIterator> > > |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1294 | class _LIBCPP_TYPE_VIS_ONLY match_results; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1295 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1296 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1297 | struct __state |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1298 | { |
| 1299 | enum |
| 1300 | { |
| 1301 | __end_state = -1000, |
| 1302 | __consume_input, // -999 |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1303 | __begin_marked_expr, // -998 |
| 1304 | __end_marked_expr, // -997 |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1305 | __pop_state, // -996 |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1306 | __accept_and_consume, // -995 |
| 1307 | __accept_but_not_consume, // -994 |
| 1308 | __reject, // -993 |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1309 | __split, |
| 1310 | __repeat |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1311 | }; |
| 1312 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1313 | int __do_; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1314 | const _CharT* __first_; |
| 1315 | const _CharT* __current_; |
| 1316 | const _CharT* __last_; |
| 1317 | vector<sub_match<const _CharT*> > __sub_matches_; |
| 1318 | vector<pair<size_t, const _CharT*> > __loop_data_; |
| 1319 | const __node<_CharT>* __node_; |
| 1320 | regex_constants::match_flag_type __flags_; |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 1321 | bool __at_first_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1322 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1323 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1324 | __state() |
| 1325 | : __do_(0), __first_(nullptr), __current_(nullptr), __last_(nullptr), |
| 1326 | __node_(nullptr), __flags_() {} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1327 | }; |
| 1328 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1329 | // __node |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1330 | |
| 1331 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1332 | class __node |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1333 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1334 | __node(const __node&); |
| 1335 | __node& operator=(const __node&); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1336 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1337 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1338 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1339 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1340 | __node() {} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1341 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1342 | virtual ~__node() {} |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1343 | |
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 | virtual void __exec(__state&) const {}; |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1346 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1347 | virtual void __exec_split(bool, __state&) const {}; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1348 | }; |
| 1349 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1350 | // __end_state |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1351 | |
| 1352 | template <class _CharT> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1353 | class __end_state |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1354 | : public __node<_CharT> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1355 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1356 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1357 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1358 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1359 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1360 | __end_state() {} |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1361 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1362 | virtual void __exec(__state&) const; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1363 | }; |
| 1364 | |
| 1365 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1366 | void |
| 1367 | __end_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1368 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1369 | __s.__do_ = __state::__end_state; |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1370 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1371 | |
| 1372 | // __has_one_state |
| 1373 | |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1374 | template <class _CharT> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1375 | class __has_one_state |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1376 | : public __node<_CharT> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1377 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1378 | __node<_CharT>* __first_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1379 | |
| 1380 | public: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1381 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1382 | explicit __has_one_state(__node<_CharT>* __s) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1383 | : __first_(__s) {} |
| 1384 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1385 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1386 | __node<_CharT>* first() const {return __first_;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1387 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1388 | __node<_CharT>*& first() {return __first_;} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1389 | }; |
| 1390 | |
| 1391 | // __owns_one_state |
| 1392 | |
| 1393 | template <class _CharT> |
| 1394 | class __owns_one_state |
| 1395 | : public __has_one_state<_CharT> |
| 1396 | { |
| 1397 | typedef __has_one_state<_CharT> base; |
| 1398 | |
| 1399 | public: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1400 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1401 | explicit __owns_one_state(__node<_CharT>* __s) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1402 | : base(__s) {} |
| 1403 | |
| 1404 | virtual ~__owns_one_state(); |
| 1405 | }; |
| 1406 | |
| 1407 | template <class _CharT> |
| 1408 | __owns_one_state<_CharT>::~__owns_one_state() |
| 1409 | { |
| 1410 | delete this->first(); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1411 | } |
| 1412 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1413 | // __empty_state |
| 1414 | |
| 1415 | template <class _CharT> |
| 1416 | class __empty_state |
| 1417 | : public __owns_one_state<_CharT> |
| 1418 | { |
| 1419 | typedef __owns_one_state<_CharT> base; |
| 1420 | |
| 1421 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1422 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1423 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1424 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1425 | explicit __empty_state(__node<_CharT>* __s) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1426 | : base(__s) {} |
| 1427 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1428 | virtual void __exec(__state&) const; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1429 | }; |
| 1430 | |
| 1431 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1432 | void |
| 1433 | __empty_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1434 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1435 | __s.__do_ = __state::__accept_but_not_consume; |
| 1436 | __s.__node_ = this->first(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1437 | } |
| 1438 | |
| 1439 | // __empty_non_own_state |
| 1440 | |
| 1441 | template <class _CharT> |
| 1442 | class __empty_non_own_state |
| 1443 | : public __has_one_state<_CharT> |
| 1444 | { |
| 1445 | typedef __has_one_state<_CharT> base; |
| 1446 | |
| 1447 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1448 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1449 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1450 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1451 | explicit __empty_non_own_state(__node<_CharT>* __s) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1452 | : base(__s) {} |
| 1453 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1454 | virtual void __exec(__state&) const; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1455 | }; |
| 1456 | |
| 1457 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1458 | void |
| 1459 | __empty_non_own_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1460 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1461 | __s.__do_ = __state::__accept_but_not_consume; |
| 1462 | __s.__node_ = this->first(); |
| 1463 | } |
| 1464 | |
| 1465 | // __repeat_one_loop |
| 1466 | |
| 1467 | template <class _CharT> |
| 1468 | class __repeat_one_loop |
| 1469 | : public __has_one_state<_CharT> |
| 1470 | { |
| 1471 | typedef __has_one_state<_CharT> base; |
| 1472 | |
| 1473 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1474 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1475 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1476 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1477 | explicit __repeat_one_loop(__node<_CharT>* __s) |
| 1478 | : base(__s) {} |
| 1479 | |
| 1480 | virtual void __exec(__state&) const; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1481 | }; |
| 1482 | |
| 1483 | template <class _CharT> |
| 1484 | void |
| 1485 | __repeat_one_loop<_CharT>::__exec(__state& __s) const |
| 1486 | { |
| 1487 | __s.__do_ = __state::__repeat; |
| 1488 | __s.__node_ = this->first(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | // __owns_two_states |
| 1492 | |
| 1493 | template <class _CharT> |
| 1494 | class __owns_two_states |
| 1495 | : public __owns_one_state<_CharT> |
| 1496 | { |
| 1497 | typedef __owns_one_state<_CharT> base; |
| 1498 | |
| 1499 | base* __second_; |
| 1500 | |
| 1501 | public: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1502 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1503 | explicit __owns_two_states(__node<_CharT>* __s1, base* __s2) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1504 | : base(__s1), __second_(__s2) {} |
| 1505 | |
| 1506 | virtual ~__owns_two_states(); |
| 1507 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1508 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1509 | base* second() const {return __second_;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1510 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1511 | base*& second() {return __second_;} |
| 1512 | }; |
| 1513 | |
| 1514 | template <class _CharT> |
| 1515 | __owns_two_states<_CharT>::~__owns_two_states() |
| 1516 | { |
| 1517 | delete __second_; |
| 1518 | } |
| 1519 | |
| 1520 | // __loop |
| 1521 | |
| 1522 | template <class _CharT> |
| 1523 | class __loop |
| 1524 | : public __owns_two_states<_CharT> |
| 1525 | { |
| 1526 | typedef __owns_two_states<_CharT> base; |
| 1527 | |
| 1528 | size_t __min_; |
| 1529 | size_t __max_; |
| 1530 | unsigned __loop_id_; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1531 | unsigned __mexp_begin_; |
| 1532 | unsigned __mexp_end_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1533 | bool __greedy_; |
| 1534 | |
| 1535 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1536 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1537 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1538 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1539 | explicit __loop(unsigned __loop_id, |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1540 | __node<_CharT>* __s1, __owns_one_state<_CharT>* __s2, |
| 1541 | unsigned __mexp_begin, unsigned __mexp_end, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1542 | bool __greedy = true, |
| 1543 | size_t __min = 0, |
| 1544 | size_t __max = numeric_limits<size_t>::max()) |
| 1545 | : base(__s1, __s2), __min_(__min), __max_(__max), __loop_id_(__loop_id), |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1546 | __mexp_begin_(__mexp_begin), __mexp_end_(__mexp_end), |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1547 | __greedy_(__greedy) {} |
| 1548 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1549 | virtual void __exec(__state& __s) const; |
| 1550 | virtual void __exec_split(bool __second, __state& __s) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1551 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1552 | private: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1553 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1554 | void __init_repeat(__state& __s) const |
| 1555 | { |
| 1556 | __s.__loop_data_[__loop_id_].second = __s.__current_; |
| 1557 | for (size_t __i = __mexp_begin_-1; __i != __mexp_end_-1; ++__i) |
| 1558 | { |
| 1559 | __s.__sub_matches_[__i].first = __s.__last_; |
| 1560 | __s.__sub_matches_[__i].second = __s.__last_; |
| 1561 | __s.__sub_matches_[__i].matched = false; |
| 1562 | } |
| 1563 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1564 | }; |
| 1565 | |
| 1566 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1567 | void |
| 1568 | __loop<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1569 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1570 | if (__s.__do_ == __state::__repeat) |
| 1571 | { |
| 1572 | bool __do_repeat = ++__s.__loop_data_[__loop_id_].first < __max_; |
| 1573 | bool __do_alt = __s.__loop_data_[__loop_id_].first >= __min_; |
| 1574 | if (__do_repeat && __do_alt && |
| 1575 | __s.__loop_data_[__loop_id_].second == __s.__current_) |
| 1576 | __do_repeat = false; |
| 1577 | if (__do_repeat && __do_alt) |
| 1578 | __s.__do_ = __state::__split; |
| 1579 | else if (__do_repeat) |
| 1580 | { |
| 1581 | __s.__do_ = __state::__accept_but_not_consume; |
| 1582 | __s.__node_ = this->first(); |
| 1583 | __init_repeat(__s); |
| 1584 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1585 | else |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1586 | { |
| 1587 | __s.__do_ = __state::__accept_but_not_consume; |
| 1588 | __s.__node_ = this->second(); |
| 1589 | } |
| 1590 | } |
| 1591 | else |
| 1592 | { |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 1593 | __s.__loop_data_[__loop_id_].first = 0; |
| 1594 | bool __do_repeat = 0 < __max_; |
| 1595 | bool __do_alt = 0 >= __min_; |
| 1596 | if (__do_repeat && __do_alt) |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1597 | __s.__do_ = __state::__split; |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 1598 | else if (__do_repeat) |
| 1599 | { |
| 1600 | __s.__do_ = __state::__accept_but_not_consume; |
| 1601 | __s.__node_ = this->first(); |
| 1602 | __init_repeat(__s); |
| 1603 | } |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1604 | else |
| 1605 | { |
| 1606 | __s.__do_ = __state::__accept_but_not_consume; |
| 1607 | __s.__node_ = this->second(); |
| 1608 | } |
| 1609 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1610 | } |
| 1611 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1612 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1613 | void |
| 1614 | __loop<_CharT>::__exec_split(bool __second, __state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1615 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1616 | __s.__do_ = __state::__accept_but_not_consume; |
| 1617 | if (__greedy_ != __second) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1618 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1619 | __s.__node_ = this->first(); |
| 1620 | __init_repeat(__s); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1621 | } |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1622 | else |
| 1623 | __s.__node_ = this->second(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1624 | } |
| 1625 | |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1626 | // __alternate |
| 1627 | |
| 1628 | template <class _CharT> |
| 1629 | class __alternate |
| 1630 | : public __owns_two_states<_CharT> |
| 1631 | { |
| 1632 | typedef __owns_two_states<_CharT> base; |
| 1633 | |
| 1634 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1635 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1636 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1637 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1638 | explicit __alternate(__owns_one_state<_CharT>* __s1, |
| 1639 | __owns_one_state<_CharT>* __s2) |
| 1640 | : base(__s1, __s2) {} |
| 1641 | |
| 1642 | virtual void __exec(__state& __s) const; |
| 1643 | virtual void __exec_split(bool __second, __state& __s) const; |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1644 | }; |
| 1645 | |
| 1646 | template <class _CharT> |
| 1647 | void |
| 1648 | __alternate<_CharT>::__exec(__state& __s) const |
| 1649 | { |
| 1650 | __s.__do_ = __state::__split; |
| 1651 | } |
| 1652 | |
| 1653 | template <class _CharT> |
| 1654 | void |
| 1655 | __alternate<_CharT>::__exec_split(bool __second, __state& __s) const |
| 1656 | { |
| 1657 | __s.__do_ = __state::__accept_but_not_consume; |
Howard Hinnant | 1371b2e | 2010-07-22 14:12:20 +0000 | [diff] [blame] | 1658 | if (__second) |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1659 | __s.__node_ = this->second(); |
Howard Hinnant | 1371b2e | 2010-07-22 14:12:20 +0000 | [diff] [blame] | 1660 | else |
| 1661 | __s.__node_ = this->first(); |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1662 | } |
| 1663 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1664 | // __begin_marked_subexpression |
| 1665 | |
| 1666 | template <class _CharT> |
| 1667 | class __begin_marked_subexpression |
| 1668 | : public __owns_one_state<_CharT> |
| 1669 | { |
| 1670 | typedef __owns_one_state<_CharT> base; |
| 1671 | |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1672 | unsigned __mexp_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1673 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1674 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1675 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1676 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1677 | explicit __begin_marked_subexpression(unsigned __mexp, __node<_CharT>* __s) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1678 | : base(__s), __mexp_(__mexp) {} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1679 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1680 | virtual void __exec(__state&) const; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1681 | }; |
| 1682 | |
| 1683 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1684 | void |
| 1685 | __begin_marked_subexpression<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1686 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1687 | __s.__do_ = __state::__accept_but_not_consume; |
| 1688 | __s.__sub_matches_[__mexp_-1].first = __s.__current_; |
| 1689 | __s.__node_ = this->first(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1690 | } |
| 1691 | |
| 1692 | // __end_marked_subexpression |
| 1693 | |
| 1694 | template <class _CharT> |
| 1695 | class __end_marked_subexpression |
| 1696 | : public __owns_one_state<_CharT> |
| 1697 | { |
| 1698 | typedef __owns_one_state<_CharT> base; |
| 1699 | |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1700 | unsigned __mexp_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1701 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1702 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1703 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1704 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1705 | explicit __end_marked_subexpression(unsigned __mexp, __node<_CharT>* __s) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1706 | : base(__s), __mexp_(__mexp) {} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1707 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1708 | virtual void __exec(__state&) const; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1709 | }; |
| 1710 | |
| 1711 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1712 | void |
| 1713 | __end_marked_subexpression<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1714 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1715 | __s.__do_ = __state::__accept_but_not_consume; |
| 1716 | __s.__sub_matches_[__mexp_-1].second = __s.__current_; |
| 1717 | __s.__sub_matches_[__mexp_-1].matched = true; |
| 1718 | __s.__node_ = this->first(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1719 | } |
| 1720 | |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1721 | // __back_ref |
| 1722 | |
| 1723 | template <class _CharT> |
| 1724 | class __back_ref |
| 1725 | : public __owns_one_state<_CharT> |
| 1726 | { |
| 1727 | typedef __owns_one_state<_CharT> base; |
| 1728 | |
| 1729 | unsigned __mexp_; |
| 1730 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1731 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1732 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1733 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1734 | explicit __back_ref(unsigned __mexp, __node<_CharT>* __s) |
| 1735 | : base(__s), __mexp_(__mexp) {} |
| 1736 | |
| 1737 | virtual void __exec(__state&) const; |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1738 | }; |
| 1739 | |
| 1740 | template <class _CharT> |
| 1741 | void |
| 1742 | __back_ref<_CharT>::__exec(__state& __s) const |
| 1743 | { |
Marshall Clow | 70e8f59 | 2015-08-24 15:57:09 +0000 | [diff] [blame] | 1744 | if (__mexp_ > __s.__sub_matches_.size()) |
| 1745 | __throw_regex_error<regex_constants::error_backref>(); |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1746 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1747 | if (__sm.matched) |
| 1748 | { |
| 1749 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1750 | if (__s.__last_ - __s.__current_ >= __len && |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1751 | _VSTD::equal(__sm.first, __sm.second, __s.__current_)) |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1752 | { |
| 1753 | __s.__do_ = __state::__accept_but_not_consume; |
| 1754 | __s.__current_ += __len; |
| 1755 | __s.__node_ = this->first(); |
| 1756 | } |
| 1757 | else |
| 1758 | { |
| 1759 | __s.__do_ = __state::__reject; |
| 1760 | __s.__node_ = nullptr; |
| 1761 | } |
| 1762 | } |
| 1763 | else |
| 1764 | { |
| 1765 | __s.__do_ = __state::__reject; |
| 1766 | __s.__node_ = nullptr; |
| 1767 | } |
| 1768 | } |
| 1769 | |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1770 | // __back_ref_icase |
| 1771 | |
| 1772 | template <class _CharT, class _Traits> |
| 1773 | class __back_ref_icase |
| 1774 | : public __owns_one_state<_CharT> |
| 1775 | { |
| 1776 | typedef __owns_one_state<_CharT> base; |
| 1777 | |
| 1778 | _Traits __traits_; |
| 1779 | unsigned __mexp_; |
| 1780 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1781 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1782 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1783 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1784 | explicit __back_ref_icase(const _Traits& __traits, unsigned __mexp, |
| 1785 | __node<_CharT>* __s) |
| 1786 | : base(__s), __traits_(__traits), __mexp_(__mexp) {} |
| 1787 | |
| 1788 | virtual void __exec(__state&) const; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1789 | }; |
| 1790 | |
| 1791 | template <class _CharT, class _Traits> |
| 1792 | void |
| 1793 | __back_ref_icase<_CharT, _Traits>::__exec(__state& __s) const |
| 1794 | { |
| 1795 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1796 | if (__sm.matched) |
| 1797 | { |
| 1798 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1799 | if (__s.__last_ - __s.__current_ >= __len) |
| 1800 | { |
| 1801 | for (ptrdiff_t __i = 0; __i < __len; ++__i) |
| 1802 | { |
| 1803 | if (__traits_.translate_nocase(__sm.first[__i]) != |
| 1804 | __traits_.translate_nocase(__s.__current_[__i])) |
| 1805 | goto __not_equal; |
| 1806 | } |
| 1807 | __s.__do_ = __state::__accept_but_not_consume; |
| 1808 | __s.__current_ += __len; |
| 1809 | __s.__node_ = this->first(); |
| 1810 | } |
| 1811 | else |
| 1812 | { |
| 1813 | __s.__do_ = __state::__reject; |
| 1814 | __s.__node_ = nullptr; |
| 1815 | } |
| 1816 | } |
| 1817 | else |
| 1818 | { |
| 1819 | __not_equal: |
| 1820 | __s.__do_ = __state::__reject; |
| 1821 | __s.__node_ = nullptr; |
| 1822 | } |
| 1823 | } |
| 1824 | |
| 1825 | // __back_ref_collate |
| 1826 | |
| 1827 | template <class _CharT, class _Traits> |
| 1828 | class __back_ref_collate |
| 1829 | : public __owns_one_state<_CharT> |
| 1830 | { |
| 1831 | typedef __owns_one_state<_CharT> base; |
| 1832 | |
| 1833 | _Traits __traits_; |
| 1834 | unsigned __mexp_; |
| 1835 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1836 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1837 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1838 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1839 | explicit __back_ref_collate(const _Traits& __traits, unsigned __mexp, |
| 1840 | __node<_CharT>* __s) |
| 1841 | : base(__s), __traits_(__traits), __mexp_(__mexp) {} |
| 1842 | |
| 1843 | virtual void __exec(__state&) const; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1844 | }; |
| 1845 | |
| 1846 | template <class _CharT, class _Traits> |
| 1847 | void |
| 1848 | __back_ref_collate<_CharT, _Traits>::__exec(__state& __s) const |
| 1849 | { |
| 1850 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1851 | if (__sm.matched) |
| 1852 | { |
| 1853 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1854 | if (__s.__last_ - __s.__current_ >= __len) |
| 1855 | { |
| 1856 | for (ptrdiff_t __i = 0; __i < __len; ++__i) |
| 1857 | { |
| 1858 | if (__traits_.translate(__sm.first[__i]) != |
| 1859 | __traits_.translate(__s.__current_[__i])) |
| 1860 | goto __not_equal; |
| 1861 | } |
| 1862 | __s.__do_ = __state::__accept_but_not_consume; |
| 1863 | __s.__current_ += __len; |
| 1864 | __s.__node_ = this->first(); |
| 1865 | } |
| 1866 | else |
| 1867 | { |
| 1868 | __s.__do_ = __state::__reject; |
| 1869 | __s.__node_ = nullptr; |
| 1870 | } |
| 1871 | } |
| 1872 | else |
| 1873 | { |
| 1874 | __not_equal: |
| 1875 | __s.__do_ = __state::__reject; |
| 1876 | __s.__node_ = nullptr; |
| 1877 | } |
| 1878 | } |
| 1879 | |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1880 | // __word_boundary |
| 1881 | |
| 1882 | template <class _CharT, class _Traits> |
| 1883 | class __word_boundary |
| 1884 | : public __owns_one_state<_CharT> |
| 1885 | { |
| 1886 | typedef __owns_one_state<_CharT> base; |
| 1887 | |
| 1888 | _Traits __traits_; |
| 1889 | bool __invert_; |
| 1890 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1891 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1892 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1893 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1894 | explicit __word_boundary(const _Traits& __traits, bool __invert, |
| 1895 | __node<_CharT>* __s) |
| 1896 | : base(__s), __traits_(__traits), __invert_(__invert) {} |
| 1897 | |
| 1898 | virtual void __exec(__state&) const; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1899 | }; |
| 1900 | |
| 1901 | template <class _CharT, class _Traits> |
| 1902 | void |
| 1903 | __word_boundary<_CharT, _Traits>::__exec(__state& __s) const |
| 1904 | { |
| 1905 | bool __is_word_b = false; |
| 1906 | if (__s.__first_ != __s.__last_) |
| 1907 | { |
| 1908 | if (__s.__current_ == __s.__last_) |
| 1909 | { |
| 1910 | if (!(__s.__flags_ & regex_constants::match_not_eow)) |
| 1911 | { |
| 1912 | _CharT __c = __s.__current_[-1]; |
| 1913 | __is_word_b = __c == '_' || |
| 1914 | __traits_.isctype(__c, ctype_base::alnum); |
| 1915 | } |
| 1916 | } |
Howard Hinnant | f3dcca0 | 2010-07-29 15:17:28 +0000 | [diff] [blame] | 1917 | else if (__s.__current_ == __s.__first_ && |
| 1918 | !(__s.__flags_ & regex_constants::match_prev_avail)) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1919 | { |
| 1920 | if (!(__s.__flags_ & regex_constants::match_not_bow)) |
| 1921 | { |
| 1922 | _CharT __c = *__s.__current_; |
| 1923 | __is_word_b = __c == '_' || |
| 1924 | __traits_.isctype(__c, ctype_base::alnum); |
| 1925 | } |
| 1926 | } |
| 1927 | else |
| 1928 | { |
| 1929 | _CharT __c1 = __s.__current_[-1]; |
| 1930 | _CharT __c2 = *__s.__current_; |
| 1931 | bool __is_c1_b = __c1 == '_' || |
| 1932 | __traits_.isctype(__c1, ctype_base::alnum); |
| 1933 | bool __is_c2_b = __c2 == '_' || |
| 1934 | __traits_.isctype(__c2, ctype_base::alnum); |
| 1935 | __is_word_b = __is_c1_b != __is_c2_b; |
| 1936 | } |
| 1937 | } |
| 1938 | if (__is_word_b != __invert_) |
| 1939 | { |
| 1940 | __s.__do_ = __state::__accept_but_not_consume; |
| 1941 | __s.__node_ = this->first(); |
| 1942 | } |
| 1943 | else |
| 1944 | { |
| 1945 | __s.__do_ = __state::__reject; |
| 1946 | __s.__node_ = nullptr; |
| 1947 | } |
| 1948 | } |
| 1949 | |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 1950 | // __l_anchor |
| 1951 | |
| 1952 | template <class _CharT> |
| 1953 | class __l_anchor |
| 1954 | : public __owns_one_state<_CharT> |
| 1955 | { |
| 1956 | typedef __owns_one_state<_CharT> base; |
| 1957 | |
| 1958 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1959 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 1960 | |
| 1961 | _LIBCPP_INLINE_VISIBILITY |
| 1962 | __l_anchor(__node<_CharT>* __s) |
| 1963 | : base(__s) {} |
| 1964 | |
| 1965 | virtual void __exec(__state&) const; |
| 1966 | }; |
| 1967 | |
| 1968 | template <class _CharT> |
| 1969 | void |
| 1970 | __l_anchor<_CharT>::__exec(__state& __s) const |
| 1971 | { |
Marshall Clow | 64befb5 | 2015-03-19 17:05:59 +0000 | [diff] [blame] | 1972 | if (__s.__at_first_ && __s.__current_ == __s.__first_ && |
| 1973 | !(__s.__flags_ & regex_constants::match_not_bol)) |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 1974 | { |
| 1975 | __s.__do_ = __state::__accept_but_not_consume; |
| 1976 | __s.__node_ = this->first(); |
| 1977 | } |
| 1978 | else |
| 1979 | { |
| 1980 | __s.__do_ = __state::__reject; |
| 1981 | __s.__node_ = nullptr; |
| 1982 | } |
| 1983 | } |
| 1984 | |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 1985 | // __r_anchor |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1986 | |
| 1987 | template <class _CharT> |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 1988 | class __r_anchor |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1989 | : public __owns_one_state<_CharT> |
| 1990 | { |
| 1991 | typedef __owns_one_state<_CharT> base; |
| 1992 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1993 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1994 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1995 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1996 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1997 | __r_anchor(__node<_CharT>* __s) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 1998 | : base(__s) {} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1999 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2000 | virtual void __exec(__state&) const; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2001 | }; |
| 2002 | |
| 2003 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2004 | void |
| 2005 | __r_anchor<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2006 | { |
Marshall Clow | 64befb5 | 2015-03-19 17:05:59 +0000 | [diff] [blame] | 2007 | if (__s.__current_ == __s.__last_ && |
| 2008 | !(__s.__flags_ & regex_constants::match_not_eol)) |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2009 | { |
| 2010 | __s.__do_ = __state::__accept_but_not_consume; |
| 2011 | __s.__node_ = this->first(); |
| 2012 | } |
| 2013 | else |
| 2014 | { |
| 2015 | __s.__do_ = __state::__reject; |
| 2016 | __s.__node_ = nullptr; |
| 2017 | } |
| 2018 | } |
| 2019 | |
| 2020 | // __match_any |
| 2021 | |
| 2022 | template <class _CharT> |
| 2023 | class __match_any |
| 2024 | : public __owns_one_state<_CharT> |
| 2025 | { |
| 2026 | typedef __owns_one_state<_CharT> base; |
| 2027 | |
| 2028 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2029 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2030 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2031 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2032 | __match_any(__node<_CharT>* __s) |
| 2033 | : base(__s) {} |
| 2034 | |
| 2035 | virtual void __exec(__state&) const; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2036 | }; |
| 2037 | |
| 2038 | template <class _CharT> |
| 2039 | void |
| 2040 | __match_any<_CharT>::__exec(__state& __s) const |
| 2041 | { |
| 2042 | if (__s.__current_ != __s.__last_ && *__s.__current_ != 0) |
| 2043 | { |
| 2044 | __s.__do_ = __state::__accept_and_consume; |
| 2045 | ++__s.__current_; |
| 2046 | __s.__node_ = this->first(); |
| 2047 | } |
| 2048 | else |
| 2049 | { |
| 2050 | __s.__do_ = __state::__reject; |
| 2051 | __s.__node_ = nullptr; |
| 2052 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2053 | } |
| 2054 | |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2055 | // __match_any_but_newline |
| 2056 | |
| 2057 | template <class _CharT> |
| 2058 | class __match_any_but_newline |
| 2059 | : public __owns_one_state<_CharT> |
| 2060 | { |
| 2061 | typedef __owns_one_state<_CharT> base; |
| 2062 | |
| 2063 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2064 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2065 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2066 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2067 | __match_any_but_newline(__node<_CharT>* __s) |
| 2068 | : base(__s) {} |
| 2069 | |
| 2070 | virtual void __exec(__state&) const; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2071 | }; |
| 2072 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2073 | template <> _LIBCPP_FUNC_VIS void __match_any_but_newline<char>::__exec(__state&) const; |
| 2074 | template <> _LIBCPP_FUNC_VIS void __match_any_but_newline<wchar_t>::__exec(__state&) const; |
| 2075 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2076 | // __match_char |
| 2077 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2078 | template <class _CharT> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2079 | class __match_char |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2080 | : public __owns_one_state<_CharT> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2081 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2082 | typedef __owns_one_state<_CharT> base; |
| 2083 | |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2084 | _CharT __c_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2085 | |
| 2086 | __match_char(const __match_char&); |
| 2087 | __match_char& operator=(const __match_char&); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2088 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2089 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2090 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2091 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2092 | __match_char(_CharT __c, __node<_CharT>* __s) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2093 | : base(__s), __c_(__c) {} |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2094 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2095 | virtual void __exec(__state&) const; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2096 | }; |
| 2097 | |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2098 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2099 | void |
| 2100 | __match_char<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2101 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2102 | if (__s.__current_ != __s.__last_ && *__s.__current_ == __c_) |
| 2103 | { |
| 2104 | __s.__do_ = __state::__accept_and_consume; |
| 2105 | ++__s.__current_; |
| 2106 | __s.__node_ = this->first(); |
| 2107 | } |
| 2108 | else |
| 2109 | { |
| 2110 | __s.__do_ = __state::__reject; |
| 2111 | __s.__node_ = nullptr; |
| 2112 | } |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2113 | } |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2114 | |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2115 | // __match_char_icase |
| 2116 | |
| 2117 | template <class _CharT, class _Traits> |
| 2118 | class __match_char_icase |
| 2119 | : public __owns_one_state<_CharT> |
| 2120 | { |
| 2121 | typedef __owns_one_state<_CharT> base; |
| 2122 | |
| 2123 | _Traits __traits_; |
| 2124 | _CharT __c_; |
| 2125 | |
| 2126 | __match_char_icase(const __match_char_icase&); |
| 2127 | __match_char_icase& operator=(const __match_char_icase&); |
| 2128 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2129 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2130 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2131 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2132 | __match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s) |
| 2133 | : base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {} |
| 2134 | |
| 2135 | virtual void __exec(__state&) const; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2136 | }; |
| 2137 | |
| 2138 | template <class _CharT, class _Traits> |
| 2139 | void |
| 2140 | __match_char_icase<_CharT, _Traits>::__exec(__state& __s) const |
| 2141 | { |
| 2142 | if (__s.__current_ != __s.__last_ && |
| 2143 | __traits_.translate_nocase(*__s.__current_) == __c_) |
| 2144 | { |
| 2145 | __s.__do_ = __state::__accept_and_consume; |
| 2146 | ++__s.__current_; |
| 2147 | __s.__node_ = this->first(); |
| 2148 | } |
| 2149 | else |
| 2150 | { |
| 2151 | __s.__do_ = __state::__reject; |
| 2152 | __s.__node_ = nullptr; |
| 2153 | } |
| 2154 | } |
| 2155 | |
| 2156 | // __match_char_collate |
| 2157 | |
| 2158 | template <class _CharT, class _Traits> |
| 2159 | class __match_char_collate |
| 2160 | : public __owns_one_state<_CharT> |
| 2161 | { |
| 2162 | typedef __owns_one_state<_CharT> base; |
| 2163 | |
| 2164 | _Traits __traits_; |
| 2165 | _CharT __c_; |
| 2166 | |
| 2167 | __match_char_collate(const __match_char_collate&); |
| 2168 | __match_char_collate& operator=(const __match_char_collate&); |
| 2169 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2170 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2171 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2172 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2173 | __match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s) |
| 2174 | : base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {} |
| 2175 | |
| 2176 | virtual void __exec(__state&) const; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2177 | }; |
| 2178 | |
| 2179 | template <class _CharT, class _Traits> |
| 2180 | void |
| 2181 | __match_char_collate<_CharT, _Traits>::__exec(__state& __s) const |
| 2182 | { |
| 2183 | if (__s.__current_ != __s.__last_ && |
| 2184 | __traits_.translate(*__s.__current_) == __c_) |
| 2185 | { |
| 2186 | __s.__do_ = __state::__accept_and_consume; |
| 2187 | ++__s.__current_; |
| 2188 | __s.__node_ = this->first(); |
| 2189 | } |
| 2190 | else |
| 2191 | { |
| 2192 | __s.__do_ = __state::__reject; |
| 2193 | __s.__node_ = nullptr; |
| 2194 | } |
| 2195 | } |
| 2196 | |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2197 | // __bracket_expression |
| 2198 | |
| 2199 | template <class _CharT, class _Traits> |
| 2200 | class __bracket_expression |
| 2201 | : public __owns_one_state<_CharT> |
| 2202 | { |
| 2203 | typedef __owns_one_state<_CharT> base; |
| 2204 | typedef typename _Traits::string_type string_type; |
| 2205 | |
| 2206 | _Traits __traits_; |
| 2207 | vector<_CharT> __chars_; |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2208 | vector<_CharT> __neg_chars_; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2209 | vector<pair<string_type, string_type> > __ranges_; |
| 2210 | vector<pair<_CharT, _CharT> > __digraphs_; |
| 2211 | vector<string_type> __equivalences_; |
Dan Albert | 1757386 | 2014-07-29 19:23:39 +0000 | [diff] [blame] | 2212 | typename regex_traits<_CharT>::char_class_type __mask_; |
| 2213 | typename regex_traits<_CharT>::char_class_type __neg_mask_; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2214 | bool __negate_; |
| 2215 | bool __icase_; |
| 2216 | bool __collate_; |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2217 | bool __might_have_digraph_; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2218 | |
| 2219 | __bracket_expression(const __bracket_expression&); |
| 2220 | __bracket_expression& operator=(const __bracket_expression&); |
| 2221 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2222 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2223 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2224 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2225 | __bracket_expression(const _Traits& __traits, __node<_CharT>* __s, |
| 2226 | bool __negate, bool __icase, bool __collate) |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2227 | : base(__s), __traits_(__traits), __mask_(), __neg_mask_(), |
| 2228 | __negate_(__negate), __icase_(__icase), __collate_(__collate), |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2229 | __might_have_digraph_(__traits_.getloc().name() != "C") {} |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2230 | |
| 2231 | virtual void __exec(__state&) const; |
| 2232 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2233 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2234 | bool __negated() const {return __negate_;} |
| 2235 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2236 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2237 | void __add_char(_CharT __c) |
| 2238 | { |
| 2239 | if (__icase_) |
| 2240 | __chars_.push_back(__traits_.translate_nocase(__c)); |
| 2241 | else if (__collate_) |
| 2242 | __chars_.push_back(__traits_.translate(__c)); |
| 2243 | else |
| 2244 | __chars_.push_back(__c); |
| 2245 | } |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2246 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2247 | void __add_neg_char(_CharT __c) |
| 2248 | { |
| 2249 | if (__icase_) |
| 2250 | __neg_chars_.push_back(__traits_.translate_nocase(__c)); |
| 2251 | else if (__collate_) |
| 2252 | __neg_chars_.push_back(__traits_.translate(__c)); |
| 2253 | else |
| 2254 | __neg_chars_.push_back(__c); |
| 2255 | } |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2256 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2257 | void __add_range(string_type __b, string_type __e) |
| 2258 | { |
| 2259 | if (__collate_) |
| 2260 | { |
| 2261 | if (__icase_) |
| 2262 | { |
| 2263 | for (size_t __i = 0; __i < __b.size(); ++__i) |
| 2264 | __b[__i] = __traits_.translate_nocase(__b[__i]); |
| 2265 | for (size_t __i = 0; __i < __e.size(); ++__i) |
| 2266 | __e[__i] = __traits_.translate_nocase(__e[__i]); |
| 2267 | } |
| 2268 | else |
| 2269 | { |
| 2270 | for (size_t __i = 0; __i < __b.size(); ++__i) |
| 2271 | __b[__i] = __traits_.translate(__b[__i]); |
| 2272 | for (size_t __i = 0; __i < __e.size(); ++__i) |
| 2273 | __e[__i] = __traits_.translate(__e[__i]); |
| 2274 | } |
| 2275 | __ranges_.push_back(make_pair( |
| 2276 | __traits_.transform(__b.begin(), __b.end()), |
| 2277 | __traits_.transform(__e.begin(), __e.end()))); |
| 2278 | } |
| 2279 | else |
| 2280 | { |
| 2281 | if (__b.size() != 1 || __e.size() != 1) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 2282 | __throw_regex_error<regex_constants::error_collate>(); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2283 | if (__icase_) |
| 2284 | { |
| 2285 | __b[0] = __traits_.translate_nocase(__b[0]); |
| 2286 | __e[0] = __traits_.translate_nocase(__e[0]); |
| 2287 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2288 | __ranges_.push_back(make_pair(_VSTD::move(__b), _VSTD::move(__e))); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2289 | } |
| 2290 | } |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2291 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2292 | void __add_digraph(_CharT __c1, _CharT __c2) |
| 2293 | { |
| 2294 | if (__icase_) |
| 2295 | __digraphs_.push_back(make_pair(__traits_.translate_nocase(__c1), |
| 2296 | __traits_.translate_nocase(__c2))); |
| 2297 | else if (__collate_) |
| 2298 | __digraphs_.push_back(make_pair(__traits_.translate(__c1), |
| 2299 | __traits_.translate(__c2))); |
| 2300 | else |
| 2301 | __digraphs_.push_back(make_pair(__c1, __c2)); |
| 2302 | } |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2303 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2304 | void __add_equivalence(const string_type& __s) |
| 2305 | {__equivalences_.push_back(__s);} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2306 | _LIBCPP_INLINE_VISIBILITY |
Dan Albert | 1757386 | 2014-07-29 19:23:39 +0000 | [diff] [blame] | 2307 | void __add_class(typename regex_traits<_CharT>::char_class_type __mask) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2308 | {__mask_ |= __mask;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2309 | _LIBCPP_INLINE_VISIBILITY |
Dan Albert | 1757386 | 2014-07-29 19:23:39 +0000 | [diff] [blame] | 2310 | void __add_neg_class(typename regex_traits<_CharT>::char_class_type __mask) |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2311 | {__neg_mask_ |= __mask;} |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2312 | }; |
| 2313 | |
| 2314 | template <class _CharT, class _Traits> |
| 2315 | void |
| 2316 | __bracket_expression<_CharT, _Traits>::__exec(__state& __s) const |
| 2317 | { |
| 2318 | bool __found = false; |
| 2319 | unsigned __consumed = 0; |
| 2320 | if (__s.__current_ != __s.__last_) |
| 2321 | { |
| 2322 | ++__consumed; |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2323 | if (__might_have_digraph_) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2324 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2325 | const _CharT* __next = _VSTD::next(__s.__current_); |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2326 | if (__next != __s.__last_) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2327 | { |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2328 | pair<_CharT, _CharT> __ch2(*__s.__current_, *__next); |
| 2329 | if (__icase_) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2330 | { |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2331 | __ch2.first = __traits_.translate_nocase(__ch2.first); |
| 2332 | __ch2.second = __traits_.translate_nocase(__ch2.second); |
| 2333 | } |
| 2334 | else if (__collate_) |
| 2335 | { |
| 2336 | __ch2.first = __traits_.translate(__ch2.first); |
| 2337 | __ch2.second = __traits_.translate(__ch2.second); |
| 2338 | } |
| 2339 | if (!__traits_.lookup_collatename(&__ch2.first, &__ch2.first+2).empty()) |
| 2340 | { |
| 2341 | // __ch2 is a digraph in this locale |
| 2342 | ++__consumed; |
| 2343 | for (size_t __i = 0; __i < __digraphs_.size(); ++__i) |
| 2344 | { |
| 2345 | if (__ch2 == __digraphs_[__i]) |
| 2346 | { |
| 2347 | __found = true; |
| 2348 | goto __exit; |
| 2349 | } |
| 2350 | } |
| 2351 | if (__collate_ && !__ranges_.empty()) |
| 2352 | { |
| 2353 | string_type __s2 = __traits_.transform(&__ch2.first, |
| 2354 | &__ch2.first + 2); |
| 2355 | for (size_t __i = 0; __i < __ranges_.size(); ++__i) |
| 2356 | { |
| 2357 | if (__ranges_[__i].first <= __s2 && |
| 2358 | __s2 <= __ranges_[__i].second) |
| 2359 | { |
| 2360 | __found = true; |
| 2361 | goto __exit; |
| 2362 | } |
| 2363 | } |
| 2364 | } |
| 2365 | if (!__equivalences_.empty()) |
| 2366 | { |
| 2367 | string_type __s2 = __traits_.transform_primary(&__ch2.first, |
| 2368 | &__ch2.first + 2); |
| 2369 | for (size_t __i = 0; __i < __equivalences_.size(); ++__i) |
| 2370 | { |
| 2371 | if (__s2 == __equivalences_[__i]) |
| 2372 | { |
| 2373 | __found = true; |
| 2374 | goto __exit; |
| 2375 | } |
| 2376 | } |
| 2377 | } |
| 2378 | if (__traits_.isctype(__ch2.first, __mask_) && |
| 2379 | __traits_.isctype(__ch2.second, __mask_)) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2380 | { |
| 2381 | __found = true; |
| 2382 | goto __exit; |
| 2383 | } |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2384 | if (!__traits_.isctype(__ch2.first, __neg_mask_) && |
| 2385 | !__traits_.isctype(__ch2.second, __neg_mask_)) |
| 2386 | { |
| 2387 | __found = true; |
| 2388 | goto __exit; |
| 2389 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2390 | goto __exit; |
| 2391 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2392 | } |
| 2393 | } |
| 2394 | // test *__s.__current_ as not a digraph |
| 2395 | _CharT __ch = *__s.__current_; |
| 2396 | if (__icase_) |
| 2397 | __ch = __traits_.translate_nocase(__ch); |
| 2398 | else if (__collate_) |
| 2399 | __ch = __traits_.translate(__ch); |
| 2400 | for (size_t __i = 0; __i < __chars_.size(); ++__i) |
| 2401 | { |
| 2402 | if (__ch == __chars_[__i]) |
| 2403 | { |
| 2404 | __found = true; |
| 2405 | goto __exit; |
| 2406 | } |
| 2407 | } |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2408 | if (!__neg_chars_.empty()) |
| 2409 | { |
| 2410 | for (size_t __i = 0; __i < __neg_chars_.size(); ++__i) |
| 2411 | { |
| 2412 | if (__ch == __neg_chars_[__i]) |
| 2413 | goto __is_neg_char; |
| 2414 | } |
| 2415 | __found = true; |
| 2416 | goto __exit; |
| 2417 | } |
| 2418 | __is_neg_char: |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2419 | if (!__ranges_.empty()) |
| 2420 | { |
| 2421 | string_type __s2 = __collate_ ? |
| 2422 | __traits_.transform(&__ch, &__ch + 1) : |
| 2423 | string_type(1, __ch); |
| 2424 | for (size_t __i = 0; __i < __ranges_.size(); ++__i) |
| 2425 | { |
| 2426 | if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second) |
| 2427 | { |
| 2428 | __found = true; |
| 2429 | goto __exit; |
| 2430 | } |
| 2431 | } |
| 2432 | } |
| 2433 | if (!__equivalences_.empty()) |
| 2434 | { |
| 2435 | string_type __s2 = __traits_.transform_primary(&__ch, &__ch + 1); |
| 2436 | for (size_t __i = 0; __i < __equivalences_.size(); ++__i) |
| 2437 | { |
| 2438 | if (__s2 == __equivalences_[__i]) |
| 2439 | { |
| 2440 | __found = true; |
| 2441 | goto __exit; |
| 2442 | } |
| 2443 | } |
| 2444 | } |
| 2445 | if (__traits_.isctype(__ch, __mask_)) |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2446 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2447 | __found = true; |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2448 | goto __exit; |
| 2449 | } |
| 2450 | if (__neg_mask_ && !__traits_.isctype(__ch, __neg_mask_)) |
| 2451 | { |
| 2452 | __found = true; |
| 2453 | goto __exit; |
| 2454 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2455 | } |
| 2456 | else |
| 2457 | __found = __negate_; // force reject |
| 2458 | __exit: |
| 2459 | if (__found != __negate_) |
| 2460 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2461 | __s.__do_ = __state::__accept_and_consume; |
| 2462 | __s.__current_ += __consumed; |
| 2463 | __s.__node_ = this->first(); |
| 2464 | } |
| 2465 | else |
| 2466 | { |
| 2467 | __s.__do_ = __state::__reject; |
| 2468 | __s.__node_ = nullptr; |
| 2469 | } |
| 2470 | } |
| 2471 | |
Howard Hinnant | 2b1b2d4 | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 2472 | template <class _CharT, class _Traits> class __lookahead; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2473 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2474 | template <class _CharT, class _Traits = regex_traits<_CharT> > |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2475 | class _LIBCPP_TYPE_VIS_ONLY basic_regex |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2476 | { |
| 2477 | public: |
| 2478 | // types: |
| 2479 | typedef _CharT value_type; |
Hubert Tong | b49c67f | 2016-08-02 21:34:48 +0000 | [diff] [blame^] | 2480 | typedef _Traits traits_type; |
| 2481 | typedef typename _Traits::string_type string_type; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2482 | typedef regex_constants::syntax_option_type flag_type; |
| 2483 | typedef typename _Traits::locale_type locale_type; |
| 2484 | |
| 2485 | private: |
| 2486 | _Traits __traits_; |
| 2487 | flag_type __flags_; |
| 2488 | unsigned __marked_count_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2489 | unsigned __loop_count_; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2490 | int __open_count_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2491 | shared_ptr<__empty_state<_CharT> > __start_; |
| 2492 | __owns_one_state<_CharT>* __end_; |
| 2493 | |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2494 | typedef _VSTD::__state<_CharT> __state; |
| 2495 | typedef _VSTD::__node<_CharT> __node; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2496 | |
| 2497 | public: |
| 2498 | // constants: |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 2499 | static const regex_constants::syntax_option_type icase = regex_constants::icase; |
| 2500 | static const regex_constants::syntax_option_type nosubs = regex_constants::nosubs; |
| 2501 | static const regex_constants::syntax_option_type optimize = regex_constants::optimize; |
| 2502 | static const regex_constants::syntax_option_type collate = regex_constants::collate; |
| 2503 | static const regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript; |
| 2504 | static const regex_constants::syntax_option_type basic = regex_constants::basic; |
| 2505 | static const regex_constants::syntax_option_type extended = regex_constants::extended; |
| 2506 | static const regex_constants::syntax_option_type awk = regex_constants::awk; |
| 2507 | static const regex_constants::syntax_option_type grep = regex_constants::grep; |
| 2508 | static const regex_constants::syntax_option_type egrep = regex_constants::egrep; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2509 | |
| 2510 | // construct/copy/destroy: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2511 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2512 | basic_regex() |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2513 | : __flags_(), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2514 | __end_(0) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2515 | {} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2516 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2517 | 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] | 2518 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2519 | __end_(0) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2520 | {__parse(__p, __p + __traits_.length(__p));} |
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(const value_type* __p, size_t __len, flag_type __f) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2523 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2524 | __end_(0) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2525 | {__parse(__p, __p + __len);} |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2526 | // basic_regex(const basic_regex&) = default; |
| 2527 | // basic_regex(basic_regex&&) = default; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2528 | template <class _ST, class _SA> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2529 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2530 | explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p, |
| 2531 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2532 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2533 | __end_(0) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2534 | {__parse(__p.begin(), __p.end());} |
| 2535 | template <class _ForwardIterator> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2536 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2537 | basic_regex(_ForwardIterator __first, _ForwardIterator __last, |
| 2538 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2539 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2540 | __end_(0) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2541 | {__parse(__first, __last);} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2542 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2543 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2544 | basic_regex(initializer_list<value_type> __il, |
| 2545 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2546 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2547 | __end_(0) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2548 | {__parse(__il.begin(), __il.end());} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2549 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2550 | |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2551 | // ~basic_regex() = default; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2552 | |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2553 | // basic_regex& operator=(const basic_regex&) = default; |
| 2554 | // basic_regex& operator=(basic_regex&&) = default; |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2555 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2556 | basic_regex& operator=(const value_type* __p) |
| 2557 | {return assign(__p);} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2558 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2559 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2560 | basic_regex& operator=(initializer_list<value_type> __il) |
| 2561 | {return assign(__il);} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2562 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2563 | template <class _ST, class _SA> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2564 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2565 | basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p) |
| 2566 | {return assign(__p);} |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2567 | |
| 2568 | // assign: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2569 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2570 | basic_regex& assign(const basic_regex& __that) |
| 2571 | {return *this = __that;} |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 2572 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 2573 | _LIBCPP_INLINE_VISIBILITY |
| 2574 | basic_regex& assign(basic_regex&& __that) _NOEXCEPT |
| 2575 | {return *this = _VSTD::move(__that);} |
| 2576 | #endif |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2577 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2578 | basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript) |
| 2579 | {return assign(__p, __p + __traits_.length(__p), __f);} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2580 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2581 | basic_regex& assign(const value_type* __p, size_t __len, flag_type __f) |
| 2582 | {return assign(__p, __p + __len, __f);} |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2583 | template <class _ST, class _SA> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2584 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2585 | basic_regex& assign(const basic_string<value_type, _ST, _SA>& __s, |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2586 | flag_type __f = regex_constants::ECMAScript) |
| 2587 | {return assign(__s.begin(), __s.end(), __f);} |
| 2588 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2589 | template <class _InputIterator> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2590 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2591 | typename enable_if |
| 2592 | < |
| 2593 | __is_input_iterator <_InputIterator>::value && |
| 2594 | !__is_forward_iterator<_InputIterator>::value, |
| 2595 | basic_regex& |
| 2596 | >::type |
| 2597 | assign(_InputIterator __first, _InputIterator __last, |
| 2598 | flag_type __f = regex_constants::ECMAScript) |
| 2599 | { |
| 2600 | basic_string<_CharT> __t(__first, __last); |
| 2601 | return assign(__t.begin(), __t.end(), __f); |
| 2602 | } |
| 2603 | |
| 2604 | private: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2605 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2606 | void __member_init(flag_type __f) |
| 2607 | { |
| 2608 | __flags_ = __f; |
| 2609 | __marked_count_ = 0; |
| 2610 | __loop_count_ = 0; |
| 2611 | __open_count_ = 0; |
| 2612 | __end_ = nullptr; |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2613 | } |
| 2614 | public: |
| 2615 | |
| 2616 | template <class _ForwardIterator> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2617 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2618 | typename enable_if |
| 2619 | < |
| 2620 | __is_forward_iterator<_ForwardIterator>::value, |
| 2621 | basic_regex& |
| 2622 | >::type |
| 2623 | assign(_ForwardIterator __first, _ForwardIterator __last, |
| 2624 | flag_type __f = regex_constants::ECMAScript) |
| 2625 | { |
Marshall Clow | 083e011 | 2015-01-13 16:49:52 +0000 | [diff] [blame] | 2626 | return assign(basic_regex(__first, __last, __f)); |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2627 | } |
| 2628 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2629 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 2630 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2631 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2632 | basic_regex& assign(initializer_list<value_type> __il, |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2633 | flag_type __f = regex_constants::ECMAScript) |
| 2634 | {return assign(__il.begin(), __il.end(), __f);} |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2635 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2636 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 2637 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2638 | // const operations: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2639 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2640 | unsigned mark_count() const {return __marked_count_;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2641 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2642 | flag_type flags() const {return __flags_;} |
| 2643 | |
| 2644 | // locale: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2645 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2646 | locale_type imbue(locale_type __loc) |
| 2647 | { |
| 2648 | __member_init(ECMAScript); |
| 2649 | __start_.reset(); |
| 2650 | return __traits_.imbue(__loc); |
| 2651 | } |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2652 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2653 | locale_type getloc() const {return __traits_.getloc();} |
| 2654 | |
| 2655 | // swap: |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2656 | void swap(basic_regex& __r); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2657 | |
| 2658 | private: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2659 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2660 | unsigned __loop_count() const {return __loop_count_;} |
| 2661 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2662 | template <class _ForwardIterator> |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2663 | _ForwardIterator |
| 2664 | __parse(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2665 | template <class _ForwardIterator> |
| 2666 | _ForwardIterator |
| 2667 | __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2668 | template <class _ForwardIterator> |
| 2669 | _ForwardIterator |
| 2670 | __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2671 | template <class _ForwardIterator> |
| 2672 | _ForwardIterator |
| 2673 | __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2674 | template <class _ForwardIterator> |
| 2675 | _ForwardIterator |
| 2676 | __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2677 | template <class _ForwardIterator> |
| 2678 | _ForwardIterator |
| 2679 | __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2680 | template <class _ForwardIterator> |
| 2681 | _ForwardIterator |
| 2682 | __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last); |
| 2683 | template <class _ForwardIterator> |
| 2684 | _ForwardIterator |
| 2685 | __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last); |
| 2686 | template <class _ForwardIterator> |
| 2687 | _ForwardIterator |
| 2688 | __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last); |
| 2689 | template <class _ForwardIterator> |
| 2690 | _ForwardIterator |
| 2691 | __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last); |
| 2692 | template <class _ForwardIterator> |
| 2693 | _ForwardIterator |
| 2694 | __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last); |
| 2695 | template <class _ForwardIterator> |
| 2696 | _ForwardIterator |
| 2697 | __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last); |
| 2698 | template <class _ForwardIterator> |
| 2699 | _ForwardIterator |
| 2700 | __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last); |
| 2701 | template <class _ForwardIterator> |
| 2702 | _ForwardIterator |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2703 | __parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last, |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2704 | __owns_one_state<_CharT>* __s, |
| 2705 | unsigned __mexp_begin, unsigned __mexp_end); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2706 | template <class _ForwardIterator> |
| 2707 | _ForwardIterator |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 2708 | __parse_ERE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last, |
| 2709 | __owns_one_state<_CharT>* __s, |
| 2710 | unsigned __mexp_begin, unsigned __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2711 | template <class _ForwardIterator> |
| 2712 | _ForwardIterator |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2713 | __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2714 | template <class _ForwardIterator> |
| 2715 | _ForwardIterator |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2716 | __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last, |
| 2717 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2718 | template <class _ForwardIterator> |
| 2719 | _ForwardIterator |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2720 | __parse_expression_term(_ForwardIterator __first, _ForwardIterator __last, |
| 2721 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2722 | template <class _ForwardIterator> |
| 2723 | _ForwardIterator |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2724 | __parse_equivalence_class(_ForwardIterator __first, _ForwardIterator __last, |
| 2725 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2726 | template <class _ForwardIterator> |
| 2727 | _ForwardIterator |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2728 | __parse_character_class(_ForwardIterator __first, _ForwardIterator __last, |
| 2729 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2730 | template <class _ForwardIterator> |
| 2731 | _ForwardIterator |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2732 | __parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last, |
| 2733 | basic_string<_CharT>& __col_sym); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2734 | template <class _ForwardIterator> |
| 2735 | _ForwardIterator |
| 2736 | __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2737 | template <class _ForwardIterator> |
| 2738 | _ForwardIterator |
| 2739 | __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2740 | template <class _ForwardIterator> |
| 2741 | _ForwardIterator |
| 2742 | __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last); |
| 2743 | template <class _ForwardIterator> |
| 2744 | _ForwardIterator |
| 2745 | __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2746 | template <class _ForwardIterator> |
| 2747 | _ForwardIterator |
| 2748 | __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last); |
| 2749 | template <class _ForwardIterator> |
| 2750 | _ForwardIterator |
| 2751 | __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last); |
| 2752 | template <class _ForwardIterator> |
| 2753 | _ForwardIterator |
| 2754 | __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 2755 | template <class _ForwardIterator> |
| 2756 | _ForwardIterator |
| 2757 | __parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2758 | template <class _ForwardIterator> |
| 2759 | _ForwardIterator |
| 2760 | __parse_alternative(_ForwardIterator __first, _ForwardIterator __last); |
| 2761 | template <class _ForwardIterator> |
| 2762 | _ForwardIterator |
| 2763 | __parse_term(_ForwardIterator __first, _ForwardIterator __last); |
| 2764 | template <class _ForwardIterator> |
| 2765 | _ForwardIterator |
| 2766 | __parse_assertion(_ForwardIterator __first, _ForwardIterator __last); |
| 2767 | template <class _ForwardIterator> |
| 2768 | _ForwardIterator |
| 2769 | __parse_atom(_ForwardIterator __first, _ForwardIterator __last); |
| 2770 | template <class _ForwardIterator> |
| 2771 | _ForwardIterator |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2772 | __parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2773 | template <class _ForwardIterator> |
| 2774 | _ForwardIterator |
| 2775 | __parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2776 | template <class _ForwardIterator> |
| 2777 | _ForwardIterator |
| 2778 | __parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2779 | template <class _ForwardIterator> |
| 2780 | _ForwardIterator |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2781 | __parse_character_escape(_ForwardIterator __first, _ForwardIterator __last, |
| 2782 | basic_string<_CharT>* __str = nullptr); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2783 | template <class _ForwardIterator> |
| 2784 | _ForwardIterator |
| 2785 | __parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 856846b | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 2786 | template <class _ForwardIterator> |
| 2787 | _ForwardIterator |
| 2788 | __parse_grep(_ForwardIterator __first, _ForwardIterator __last); |
| 2789 | template <class _ForwardIterator> |
| 2790 | _ForwardIterator |
| 2791 | __parse_egrep(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2792 | template <class _ForwardIterator> |
| 2793 | _ForwardIterator |
| 2794 | __parse_class_escape(_ForwardIterator __first, _ForwardIterator __last, |
| 2795 | basic_string<_CharT>& __str, |
| 2796 | __bracket_expression<_CharT, _Traits>* __ml); |
| 2797 | template <class _ForwardIterator> |
| 2798 | _ForwardIterator |
| 2799 | __parse_awk_escape(_ForwardIterator __first, _ForwardIterator __last, |
| 2800 | basic_string<_CharT>* __str = nullptr); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2801 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2802 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2803 | void __push_l_anchor(); |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2804 | void __push_r_anchor(); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2805 | void __push_match_any(); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2806 | void __push_match_any_but_newline(); |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2807 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2808 | void __push_greedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s, |
| 2809 | unsigned __mexp_begin = 0, unsigned __mexp_end = 0) |
| 2810 | {__push_loop(__min, numeric_limits<size_t>::max(), __s, |
| 2811 | __mexp_begin, __mexp_end);} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2812 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2813 | void __push_nongreedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s, |
| 2814 | unsigned __mexp_begin = 0, unsigned __mexp_end = 0) |
| 2815 | {__push_loop(__min, numeric_limits<size_t>::max(), __s, |
| 2816 | __mexp_begin, __mexp_end, false);} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2817 | void __push_loop(size_t __min, size_t __max, __owns_one_state<_CharT>* __s, |
| 2818 | size_t __mexp_begin = 0, size_t __mexp_end = 0, |
| 2819 | bool __greedy = true); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2820 | __bracket_expression<_CharT, _Traits>* __start_matching_list(bool __negate); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2821 | void __push_char(value_type __c); |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 2822 | void __push_back_ref(int __i); |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 2823 | void __push_alternation(__owns_one_state<_CharT>* __sa, |
| 2824 | __owns_one_state<_CharT>* __sb); |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2825 | void __push_begin_marked_subexpression(); |
| 2826 | void __push_end_marked_subexpression(unsigned); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 2827 | void __push_empty(); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2828 | void __push_word_boundary(bool); |
Howard Hinnant | cd59acc | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 2829 | void __push_lookahead(const basic_regex&, bool, unsigned); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2830 | |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2831 | template <class _Allocator> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2832 | bool |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2833 | __search(const _CharT* __first, const _CharT* __last, |
| 2834 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2835 | regex_constants::match_flag_type __flags) const; |
| 2836 | |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2837 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2838 | bool |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2839 | __match_at_start(const _CharT* __first, const _CharT* __last, |
| 2840 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2841 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2842 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2843 | bool |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2844 | __match_at_start_ecma(const _CharT* __first, const _CharT* __last, |
| 2845 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2846 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2847 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2848 | bool |
| 2849 | __match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last, |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2850 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2851 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2852 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2853 | bool |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2854 | __match_at_start_posix_subs(const _CharT* __first, const _CharT* __last, |
| 2855 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2856 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2857 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2858 | template <class _Bp, class _Ap, class _Cp, class _Tp> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2859 | friend |
| 2860 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2861 | 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] | 2862 | regex_constants::match_flag_type); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2863 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2864 | template <class _Ap, class _Cp, class _Tp> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2865 | friend |
| 2866 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2867 | regex_search(const _Cp*, const _Cp*, match_results<const _Cp*, _Ap>&, |
| 2868 | const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2869 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2870 | template <class _Bp, class _Cp, class _Tp> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2871 | friend |
| 2872 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2873 | regex_search(_Bp, _Bp, const basic_regex<_Cp, _Tp>&, |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2874 | regex_constants::match_flag_type); |
| 2875 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2876 | template <class _Cp, class _Tp> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2877 | friend |
| 2878 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2879 | regex_search(const _Cp*, const _Cp*, |
| 2880 | const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2881 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2882 | template <class _Cp, class _Ap, class _Tp> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2883 | friend |
| 2884 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2885 | 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] | 2886 | regex_constants::match_flag_type); |
| 2887 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2888 | template <class _ST, class _SA, class _Cp, class _Tp> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2889 | friend |
| 2890 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2891 | regex_search(const basic_string<_Cp, _ST, _SA>& __s, |
| 2892 | const basic_regex<_Cp, _Tp>& __e, |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2893 | regex_constants::match_flag_type __flags); |
| 2894 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2895 | template <class _ST, class _SA, class _Ap, class _Cp, class _Tp> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2896 | friend |
| 2897 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2898 | regex_search(const basic_string<_Cp, _ST, _SA>& __s, |
| 2899 | match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&, |
| 2900 | const basic_regex<_Cp, _Tp>& __e, |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2901 | regex_constants::match_flag_type __flags); |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2902 | |
Howard Hinnant | a9602d5 | 2013-06-29 23:45:43 +0000 | [diff] [blame] | 2903 | template <class _Iter, class _Ap, class _Cp, class _Tp> |
| 2904 | friend |
| 2905 | bool |
| 2906 | regex_search(__wrap_iter<_Iter> __first, |
| 2907 | __wrap_iter<_Iter> __last, |
| 2908 | match_results<__wrap_iter<_Iter>, _Ap>& __m, |
| 2909 | const basic_regex<_Cp, _Tp>& __e, |
| 2910 | regex_constants::match_flag_type __flags); |
| 2911 | |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2912 | template <class, class> friend class __lookahead; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2913 | }; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2914 | |
| 2915 | template <class _CharT, class _Traits> |
Howard Hinnant | 0a69fa1 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2916 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::icase; |
| 2917 | template <class _CharT, class _Traits> |
| 2918 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::nosubs; |
| 2919 | template <class _CharT, class _Traits> |
| 2920 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::optimize; |
| 2921 | template <class _CharT, class _Traits> |
| 2922 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::collate; |
| 2923 | template <class _CharT, class _Traits> |
| 2924 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::ECMAScript; |
| 2925 | template <class _CharT, class _Traits> |
| 2926 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::basic; |
| 2927 | template <class _CharT, class _Traits> |
| 2928 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::extended; |
| 2929 | template <class _CharT, class _Traits> |
| 2930 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::awk; |
| 2931 | template <class _CharT, class _Traits> |
| 2932 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::grep; |
| 2933 | template <class _CharT, class _Traits> |
| 2934 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::egrep; |
| 2935 | |
| 2936 | template <class _CharT, class _Traits> |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2937 | void |
| 2938 | basic_regex<_CharT, _Traits>::swap(basic_regex& __r) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2939 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2940 | using _VSTD::swap; |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2941 | swap(__traits_, __r.__traits_); |
| 2942 | swap(__flags_, __r.__flags_); |
| 2943 | swap(__marked_count_, __r.__marked_count_); |
| 2944 | swap(__loop_count_, __r.__loop_count_); |
| 2945 | swap(__open_count_, __r.__open_count_); |
| 2946 | swap(__start_, __r.__start_); |
| 2947 | swap(__end_, __r.__end_); |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2948 | } |
| 2949 | |
| 2950 | template <class _CharT, class _Traits> |
| 2951 | inline _LIBCPP_INLINE_VISIBILITY |
| 2952 | void |
| 2953 | swap(basic_regex<_CharT, _Traits>& __x, basic_regex<_CharT, _Traits>& __y) |
| 2954 | { |
| 2955 | return __x.swap(__y); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2956 | } |
| 2957 | |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2958 | // __lookahead |
| 2959 | |
| 2960 | template <class _CharT, class _Traits> |
| 2961 | class __lookahead |
| 2962 | : public __owns_one_state<_CharT> |
| 2963 | { |
| 2964 | typedef __owns_one_state<_CharT> base; |
| 2965 | |
| 2966 | basic_regex<_CharT, _Traits> __exp_; |
Howard Hinnant | cd59acc | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 2967 | unsigned __mexp_; |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2968 | bool __invert_; |
| 2969 | |
| 2970 | __lookahead(const __lookahead&); |
| 2971 | __lookahead& operator=(const __lookahead&); |
| 2972 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2973 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2974 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2975 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cd59acc | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 2976 | __lookahead(const basic_regex<_CharT, _Traits>& __exp, bool __invert, __node<_CharT>* __s, unsigned __mexp) |
Eric Fiselier | 7cc7106 | 2015-07-22 01:29:41 +0000 | [diff] [blame] | 2977 | : base(__s), __exp_(__exp), __mexp_(__mexp), __invert_(__invert) {} |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2978 | |
| 2979 | virtual void __exec(__state&) const; |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2980 | }; |
| 2981 | |
| 2982 | template <class _CharT, class _Traits> |
| 2983 | void |
| 2984 | __lookahead<_CharT, _Traits>::__exec(__state& __s) const |
| 2985 | { |
| 2986 | match_results<const _CharT*> __m; |
| 2987 | __m.__init(1 + __exp_.mark_count(), __s.__current_, __s.__last_); |
| 2988 | bool __matched = __exp_.__match_at_start_ecma(__s.__current_, __s.__last_, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2989 | __m, |
| 2990 | __s.__flags_ | regex_constants::match_continuous, |
Howard Hinnant | e57b7c4 | 2013-06-28 19:11:23 +0000 | [diff] [blame] | 2991 | __s.__at_first_ && __s.__current_ == __s.__first_); |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2992 | if (__matched != __invert_) |
| 2993 | { |
| 2994 | __s.__do_ = __state::__accept_but_not_consume; |
| 2995 | __s.__node_ = this->first(); |
Howard Hinnant | cd59acc | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 2996 | for (unsigned __i = 1; __i < __m.size(); ++__i) { |
| 2997 | __s.__sub_matches_[__mexp_ + __i - 1] = __m.__matches_[__i]; |
| 2998 | } |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2999 | } |
| 3000 | else |
| 3001 | { |
| 3002 | __s.__do_ = __state::__reject; |
| 3003 | __s.__node_ = nullptr; |
| 3004 | } |
| 3005 | } |
| 3006 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3007 | template <class _CharT, class _Traits> |
| 3008 | template <class _ForwardIterator> |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3009 | _ForwardIterator |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3010 | basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first, |
| 3011 | _ForwardIterator __last) |
| 3012 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3013 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 3014 | unique_ptr<__node> __h(new __end_state<_CharT>); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3015 | __start_.reset(new __empty_state<_CharT>(__h.get())); |
| 3016 | __h.release(); |
| 3017 | __end_ = __start_.get(); |
| 3018 | } |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 3019 | switch (__flags_ & 0x1F0) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3020 | { |
| 3021 | case ECMAScript: |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3022 | __first = __parse_ecma_exp(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3023 | break; |
| 3024 | case basic: |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3025 | __first = __parse_basic_reg_exp(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3026 | break; |
| 3027 | case extended: |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3028 | case awk: |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3029 | __first = __parse_extended_reg_exp(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3030 | break; |
| 3031 | case grep: |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3032 | __first = __parse_grep(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3033 | break; |
| 3034 | case egrep: |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3035 | __first = __parse_egrep(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3036 | break; |
| 3037 | default: |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3038 | __throw_regex_error<regex_constants::__re_err_grammar>(); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3039 | } |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3040 | return __first; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3041 | } |
| 3042 | |
| 3043 | template <class _CharT, class _Traits> |
| 3044 | template <class _ForwardIterator> |
| 3045 | _ForwardIterator |
| 3046 | basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first, |
| 3047 | _ForwardIterator __last) |
| 3048 | { |
| 3049 | if (__first != __last) |
| 3050 | { |
| 3051 | if (*__first == '^') |
| 3052 | { |
| 3053 | __push_l_anchor(); |
| 3054 | ++__first; |
| 3055 | } |
| 3056 | if (__first != __last) |
| 3057 | { |
| 3058 | __first = __parse_RE_expression(__first, __last); |
| 3059 | if (__first != __last) |
| 3060 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3061 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3062 | if (__temp == __last && *__first == '$') |
| 3063 | { |
| 3064 | __push_r_anchor(); |
| 3065 | ++__first; |
| 3066 | } |
| 3067 | } |
| 3068 | } |
| 3069 | if (__first != __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3070 | __throw_regex_error<regex_constants::__re_err_empty>(); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3071 | } |
| 3072 | return __first; |
| 3073 | } |
| 3074 | |
| 3075 | template <class _CharT, class _Traits> |
| 3076 | template <class _ForwardIterator> |
| 3077 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3078 | basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first, |
| 3079 | _ForwardIterator __last) |
| 3080 | { |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3081 | __owns_one_state<_CharT>* __sa = __end_; |
| 3082 | _ForwardIterator __temp = __parse_ERE_branch(__first, __last); |
| 3083 | if (__temp == __first) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3084 | __throw_regex_error<regex_constants::__re_err_empty>(); |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3085 | __first = __temp; |
| 3086 | while (__first != __last && *__first == '|') |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3087 | { |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3088 | __owns_one_state<_CharT>* __sb = __end_; |
| 3089 | __temp = __parse_ERE_branch(++__first, __last); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3090 | if (__temp == __first) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3091 | __throw_regex_error<regex_constants::__re_err_empty>(); |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3092 | __push_alternation(__sa, __sb); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3093 | __first = __temp; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3094 | } |
| 3095 | return __first; |
| 3096 | } |
| 3097 | |
| 3098 | template <class _CharT, class _Traits> |
| 3099 | template <class _ForwardIterator> |
| 3100 | _ForwardIterator |
| 3101 | basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first, |
| 3102 | _ForwardIterator __last) |
| 3103 | { |
| 3104 | _ForwardIterator __temp = __parse_ERE_expression(__first, __last); |
| 3105 | if (__temp == __first) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3106 | __throw_regex_error<regex_constants::__re_err_empty>(); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3107 | do |
| 3108 | { |
| 3109 | __first = __temp; |
| 3110 | __temp = __parse_ERE_expression(__first, __last); |
| 3111 | } while (__temp != __first); |
| 3112 | return __first; |
| 3113 | } |
| 3114 | |
| 3115 | template <class _CharT, class _Traits> |
| 3116 | template <class _ForwardIterator> |
| 3117 | _ForwardIterator |
| 3118 | basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first, |
| 3119 | _ForwardIterator __last) |
| 3120 | { |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3121 | __owns_one_state<_CharT>* __e = __end_; |
| 3122 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3123 | _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last); |
| 3124 | if (__temp == __first && __temp != __last) |
| 3125 | { |
| 3126 | switch (*__temp) |
| 3127 | { |
| 3128 | case '^': |
| 3129 | __push_l_anchor(); |
| 3130 | ++__temp; |
| 3131 | break; |
| 3132 | case '$': |
| 3133 | __push_r_anchor(); |
| 3134 | ++__temp; |
| 3135 | break; |
| 3136 | case '(': |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3137 | __push_begin_marked_subexpression(); |
| 3138 | unsigned __temp_count = __marked_count_; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3139 | ++__open_count_; |
| 3140 | __temp = __parse_extended_reg_exp(++__temp, __last); |
| 3141 | if (__temp == __last || *__temp != ')') |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3142 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3143 | __push_end_marked_subexpression(__temp_count); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3144 | --__open_count_; |
| 3145 | ++__temp; |
| 3146 | break; |
| 3147 | } |
| 3148 | } |
| 3149 | if (__temp != __first) |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3150 | __temp = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin+1, |
| 3151 | __marked_count_+1); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3152 | __first = __temp; |
| 3153 | return __first; |
| 3154 | } |
| 3155 | |
| 3156 | template <class _CharT, class _Traits> |
| 3157 | template <class _ForwardIterator> |
| 3158 | _ForwardIterator |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3159 | basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first, |
| 3160 | _ForwardIterator __last) |
| 3161 | { |
| 3162 | while (true) |
| 3163 | { |
| 3164 | _ForwardIterator __temp = __parse_simple_RE(__first, __last); |
| 3165 | if (__temp == __first) |
| 3166 | break; |
| 3167 | __first = __temp; |
| 3168 | } |
| 3169 | return __first; |
| 3170 | } |
| 3171 | |
| 3172 | template <class _CharT, class _Traits> |
| 3173 | template <class _ForwardIterator> |
| 3174 | _ForwardIterator |
| 3175 | basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first, |
| 3176 | _ForwardIterator __last) |
| 3177 | { |
| 3178 | if (__first != __last) |
| 3179 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3180 | __owns_one_state<_CharT>* __e = __end_; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3181 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3182 | _ForwardIterator __temp = __parse_nondupl_RE(__first, __last); |
| 3183 | if (__temp != __first) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3184 | __first = __parse_RE_dupl_symbol(__temp, __last, __e, |
| 3185 | __mexp_begin+1, __marked_count_+1); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3186 | } |
| 3187 | return __first; |
| 3188 | } |
| 3189 | |
| 3190 | template <class _CharT, class _Traits> |
| 3191 | template <class _ForwardIterator> |
| 3192 | _ForwardIterator |
| 3193 | basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first, |
| 3194 | _ForwardIterator __last) |
| 3195 | { |
| 3196 | _ForwardIterator __temp = __first; |
| 3197 | __first = __parse_one_char_or_coll_elem_RE(__first, __last); |
| 3198 | if (__temp == __first) |
| 3199 | { |
| 3200 | __temp = __parse_Back_open_paren(__first, __last); |
| 3201 | if (__temp != __first) |
| 3202 | { |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3203 | __push_begin_marked_subexpression(); |
| 3204 | unsigned __temp_count = __marked_count_; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3205 | __first = __parse_RE_expression(__temp, __last); |
| 3206 | __temp = __parse_Back_close_paren(__first, __last); |
| 3207 | if (__temp == __first) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3208 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3209 | __push_end_marked_subexpression(__temp_count); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3210 | __first = __temp; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3211 | } |
| 3212 | else |
| 3213 | __first = __parse_BACKREF(__first, __last); |
| 3214 | } |
| 3215 | return __first; |
| 3216 | } |
| 3217 | |
| 3218 | template <class _CharT, class _Traits> |
| 3219 | template <class _ForwardIterator> |
| 3220 | _ForwardIterator |
| 3221 | basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE( |
| 3222 | _ForwardIterator __first, |
| 3223 | _ForwardIterator __last) |
| 3224 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3225 | _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3226 | if (__temp == __first) |
| 3227 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3228 | __temp = __parse_QUOTED_CHAR(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3229 | if (__temp == __first) |
| 3230 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3231 | if (__temp != __last && *__temp == '.') |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3232 | { |
| 3233 | __push_match_any(); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3234 | ++__temp; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3235 | } |
| 3236 | else |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3237 | __temp = __parse_bracket_expression(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3238 | } |
| 3239 | } |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3240 | __first = __temp; |
| 3241 | return __first; |
| 3242 | } |
| 3243 | |
| 3244 | template <class _CharT, class _Traits> |
| 3245 | template <class _ForwardIterator> |
| 3246 | _ForwardIterator |
| 3247 | basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE( |
| 3248 | _ForwardIterator __first, |
| 3249 | _ForwardIterator __last) |
| 3250 | { |
| 3251 | _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last); |
| 3252 | if (__temp == __first) |
| 3253 | { |
| 3254 | __temp = __parse_QUOTED_CHAR_ERE(__first, __last); |
| 3255 | if (__temp == __first) |
| 3256 | { |
| 3257 | if (__temp != __last && *__temp == '.') |
| 3258 | { |
| 3259 | __push_match_any(); |
| 3260 | ++__temp; |
| 3261 | } |
| 3262 | else |
| 3263 | __temp = __parse_bracket_expression(__first, __last); |
| 3264 | } |
| 3265 | } |
| 3266 | __first = __temp; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3267 | return __first; |
| 3268 | } |
| 3269 | |
| 3270 | template <class _CharT, class _Traits> |
| 3271 | template <class _ForwardIterator> |
| 3272 | _ForwardIterator |
| 3273 | basic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first, |
| 3274 | _ForwardIterator __last) |
| 3275 | { |
| 3276 | if (__first != __last) |
| 3277 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3278 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3279 | if (__temp != __last) |
| 3280 | { |
| 3281 | if (*__first == '\\' && *__temp == '(') |
| 3282 | __first = ++__temp; |
| 3283 | } |
| 3284 | } |
| 3285 | return __first; |
| 3286 | } |
| 3287 | |
| 3288 | template <class _CharT, class _Traits> |
| 3289 | template <class _ForwardIterator> |
| 3290 | _ForwardIterator |
| 3291 | basic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first, |
| 3292 | _ForwardIterator __last) |
| 3293 | { |
| 3294 | if (__first != __last) |
| 3295 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3296 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3297 | if (__temp != __last) |
| 3298 | { |
| 3299 | if (*__first == '\\' && *__temp == ')') |
| 3300 | __first = ++__temp; |
| 3301 | } |
| 3302 | } |
| 3303 | return __first; |
| 3304 | } |
| 3305 | |
| 3306 | template <class _CharT, class _Traits> |
| 3307 | template <class _ForwardIterator> |
| 3308 | _ForwardIterator |
| 3309 | basic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first, |
| 3310 | _ForwardIterator __last) |
| 3311 | { |
| 3312 | if (__first != __last) |
| 3313 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3314 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3315 | if (__temp != __last) |
| 3316 | { |
| 3317 | if (*__first == '\\' && *__temp == '{') |
| 3318 | __first = ++__temp; |
| 3319 | } |
| 3320 | } |
| 3321 | return __first; |
| 3322 | } |
| 3323 | |
| 3324 | template <class _CharT, class _Traits> |
| 3325 | template <class _ForwardIterator> |
| 3326 | _ForwardIterator |
| 3327 | basic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first, |
| 3328 | _ForwardIterator __last) |
| 3329 | { |
| 3330 | if (__first != __last) |
| 3331 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3332 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3333 | if (__temp != __last) |
| 3334 | { |
| 3335 | if (*__first == '\\' && *__temp == '}') |
| 3336 | __first = ++__temp; |
| 3337 | } |
| 3338 | } |
| 3339 | return __first; |
| 3340 | } |
| 3341 | |
| 3342 | template <class _CharT, class _Traits> |
| 3343 | template <class _ForwardIterator> |
| 3344 | _ForwardIterator |
| 3345 | basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first, |
| 3346 | _ForwardIterator __last) |
| 3347 | { |
| 3348 | if (__first != __last) |
| 3349 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3350 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3351 | if (__temp != __last) |
| 3352 | { |
Marshall Clow | 97f50f6 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 3353 | if (*__first == '\\') |
| 3354 | { |
| 3355 | int __val = __traits_.value(*__temp, 10); |
| 3356 | if (__val >= 1 && __val <= 9) |
| 3357 | { |
| 3358 | __push_back_ref(__val); |
| 3359 | __first = ++__temp; |
| 3360 | } |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3361 | } |
| 3362 | } |
| 3363 | } |
| 3364 | return __first; |
| 3365 | } |
| 3366 | |
| 3367 | template <class _CharT, class _Traits> |
| 3368 | template <class _ForwardIterator> |
| 3369 | _ForwardIterator |
| 3370 | basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first, |
| 3371 | _ForwardIterator __last) |
| 3372 | { |
| 3373 | if (__first != __last) |
| 3374 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3375 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3376 | if (__temp == __last && *__first == '$') |
| 3377 | return __first; |
| 3378 | // Not called inside a bracket |
| 3379 | if (*__first == '.' || *__first == '\\' || *__first == '[') |
| 3380 | return __first; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3381 | __push_char(*__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3382 | ++__first; |
| 3383 | } |
| 3384 | return __first; |
| 3385 | } |
| 3386 | |
| 3387 | template <class _CharT, class _Traits> |
| 3388 | template <class _ForwardIterator> |
| 3389 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3390 | basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first, |
| 3391 | _ForwardIterator __last) |
| 3392 | { |
| 3393 | if (__first != __last) |
| 3394 | { |
| 3395 | switch (*__first) |
| 3396 | { |
| 3397 | case '^': |
| 3398 | case '.': |
| 3399 | case '[': |
| 3400 | case '$': |
| 3401 | case '(': |
| 3402 | case '|': |
| 3403 | case '*': |
| 3404 | case '+': |
| 3405 | case '?': |
| 3406 | case '{': |
| 3407 | case '\\': |
| 3408 | break; |
| 3409 | case ')': |
| 3410 | if (__open_count_ == 0) |
| 3411 | { |
| 3412 | __push_char(*__first); |
| 3413 | ++__first; |
| 3414 | } |
| 3415 | break; |
| 3416 | default: |
| 3417 | __push_char(*__first); |
| 3418 | ++__first; |
| 3419 | break; |
| 3420 | } |
| 3421 | } |
| 3422 | return __first; |
| 3423 | } |
| 3424 | |
| 3425 | template <class _CharT, class _Traits> |
| 3426 | template <class _ForwardIterator> |
| 3427 | _ForwardIterator |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3428 | basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first, |
| 3429 | _ForwardIterator __last) |
| 3430 | { |
| 3431 | if (__first != __last) |
| 3432 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3433 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3434 | if (__temp != __last) |
| 3435 | { |
| 3436 | if (*__first == '\\') |
| 3437 | { |
| 3438 | switch (*__temp) |
| 3439 | { |
| 3440 | case '^': |
| 3441 | case '.': |
| 3442 | case '*': |
| 3443 | case '[': |
| 3444 | case '$': |
| 3445 | case '\\': |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3446 | __push_char(*__temp); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3447 | __first = ++__temp; |
| 3448 | break; |
| 3449 | } |
| 3450 | } |
| 3451 | } |
| 3452 | } |
| 3453 | return __first; |
| 3454 | } |
| 3455 | |
| 3456 | template <class _CharT, class _Traits> |
| 3457 | template <class _ForwardIterator> |
| 3458 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3459 | basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first, |
| 3460 | _ForwardIterator __last) |
| 3461 | { |
| 3462 | if (__first != __last) |
| 3463 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3464 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3465 | if (__temp != __last) |
| 3466 | { |
| 3467 | if (*__first == '\\') |
| 3468 | { |
| 3469 | switch (*__temp) |
| 3470 | { |
| 3471 | case '^': |
| 3472 | case '.': |
| 3473 | case '*': |
| 3474 | case '[': |
| 3475 | case '$': |
| 3476 | case '\\': |
| 3477 | case '(': |
| 3478 | case ')': |
| 3479 | case '|': |
| 3480 | case '+': |
| 3481 | case '?': |
| 3482 | case '{': |
Howard Hinnant | c1ecd97 | 2013-06-28 20:31:05 +0000 | [diff] [blame] | 3483 | case '}': |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3484 | __push_char(*__temp); |
| 3485 | __first = ++__temp; |
| 3486 | break; |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3487 | default: |
| 3488 | if ((__flags_ & 0x1F0) == awk) |
| 3489 | __first = __parse_awk_escape(++__first, __last); |
| 3490 | break; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3491 | } |
| 3492 | } |
| 3493 | } |
| 3494 | } |
| 3495 | return __first; |
| 3496 | } |
| 3497 | |
| 3498 | template <class _CharT, class _Traits> |
| 3499 | template <class _ForwardIterator> |
| 3500 | _ForwardIterator |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3501 | basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3502 | _ForwardIterator __last, |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3503 | __owns_one_state<_CharT>* __s, |
| 3504 | unsigned __mexp_begin, |
| 3505 | unsigned __mexp_end) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3506 | { |
| 3507 | if (__first != __last) |
| 3508 | { |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3509 | if (*__first == '*') |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3510 | { |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3511 | __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3512 | ++__first; |
| 3513 | } |
| 3514 | else |
| 3515 | { |
| 3516 | _ForwardIterator __temp = __parse_Back_open_brace(__first, __last); |
| 3517 | if (__temp != __first) |
| 3518 | { |
| 3519 | int __min = 0; |
| 3520 | __first = __temp; |
| 3521 | __temp = __parse_DUP_COUNT(__first, __last, __min); |
| 3522 | if (__temp == __first) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3523 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3524 | __first = __temp; |
| 3525 | if (__first == __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3526 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3527 | if (*__first != ',') |
| 3528 | { |
| 3529 | __temp = __parse_Back_close_brace(__first, __last); |
| 3530 | if (__temp == __first) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3531 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 3532 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, |
| 3533 | true); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3534 | __first = __temp; |
| 3535 | } |
| 3536 | else |
| 3537 | { |
| 3538 | ++__first; // consume ',' |
| 3539 | int __max = -1; |
| 3540 | __first = __parse_DUP_COUNT(__first, __last, __max); |
| 3541 | __temp = __parse_Back_close_brace(__first, __last); |
| 3542 | if (__temp == __first) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3543 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3544 | if (__max == -1) |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3545 | __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3546 | else |
| 3547 | { |
| 3548 | if (__max < __min) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3549 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 3550 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, |
| 3551 | true); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3552 | } |
| 3553 | __first = __temp; |
| 3554 | } |
| 3555 | } |
| 3556 | } |
| 3557 | } |
| 3558 | return __first; |
| 3559 | } |
| 3560 | |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3561 | template <class _CharT, class _Traits> |
| 3562 | template <class _ForwardIterator> |
| 3563 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3564 | basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first, |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3565 | _ForwardIterator __last, |
| 3566 | __owns_one_state<_CharT>* __s, |
| 3567 | unsigned __mexp_begin, |
| 3568 | unsigned __mexp_end) |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3569 | { |
| 3570 | if (__first != __last) |
| 3571 | { |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3572 | unsigned __grammar = __flags_ & 0x1F0; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3573 | switch (*__first) |
| 3574 | { |
| 3575 | case '*': |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3576 | ++__first; |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3577 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3578 | { |
| 3579 | ++__first; |
| 3580 | __push_nongreedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
| 3581 | } |
| 3582 | else |
| 3583 | __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3584 | break; |
| 3585 | case '+': |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3586 | ++__first; |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3587 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3588 | { |
| 3589 | ++__first; |
| 3590 | __push_nongreedy_inf_repeat(1, __s, __mexp_begin, __mexp_end); |
| 3591 | } |
| 3592 | else |
| 3593 | __push_greedy_inf_repeat(1, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3594 | break; |
| 3595 | case '?': |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3596 | ++__first; |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3597 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3598 | { |
| 3599 | ++__first; |
| 3600 | __push_loop(0, 1, __s, __mexp_begin, __mexp_end, false); |
| 3601 | } |
| 3602 | else |
| 3603 | __push_loop(0, 1, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3604 | break; |
| 3605 | case '{': |
| 3606 | { |
| 3607 | int __min; |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3608 | _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3609 | if (__temp == __first) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3610 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3611 | __first = __temp; |
| 3612 | if (__first == __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3613 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3614 | switch (*__first) |
| 3615 | { |
| 3616 | case '}': |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3617 | ++__first; |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3618 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3619 | { |
| 3620 | ++__first; |
| 3621 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, false); |
| 3622 | } |
| 3623 | else |
| 3624 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3625 | break; |
| 3626 | case ',': |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3627 | ++__first; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3628 | if (__first == __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3629 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3630 | if (*__first == '}') |
| 3631 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3632 | ++__first; |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3633 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3634 | { |
| 3635 | ++__first; |
| 3636 | __push_nongreedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
| 3637 | } |
| 3638 | else |
| 3639 | __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3640 | } |
| 3641 | else |
| 3642 | { |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3643 | int __max = -1; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3644 | __temp = __parse_DUP_COUNT(__first, __last, __max); |
| 3645 | if (__temp == __first) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3646 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3647 | __first = __temp; |
| 3648 | if (__first == __last || *__first != '}') |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3649 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3650 | ++__first; |
| 3651 | if (__max < __min) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3652 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3653 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3654 | { |
| 3655 | ++__first; |
| 3656 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, false); |
| 3657 | } |
| 3658 | else |
| 3659 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3660 | } |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3661 | break; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3662 | default: |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3663 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3664 | } |
| 3665 | } |
| 3666 | break; |
| 3667 | } |
| 3668 | } |
| 3669 | return __first; |
| 3670 | } |
| 3671 | |
| 3672 | template <class _CharT, class _Traits> |
| 3673 | template <class _ForwardIterator> |
| 3674 | _ForwardIterator |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3675 | basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first, |
| 3676 | _ForwardIterator __last) |
| 3677 | { |
| 3678 | if (__first != __last && *__first == '[') |
| 3679 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3680 | ++__first; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3681 | if (__first == __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3682 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3683 | bool __negate = false; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3684 | if (*__first == '^') |
| 3685 | { |
| 3686 | ++__first; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3687 | __negate = true; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3688 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3689 | __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate); |
| 3690 | // __ml owned by *this |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3691 | if (__first == __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3692 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3693 | if ((__flags_ & 0x1F0) != ECMAScript && *__first == ']') |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3694 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3695 | __ml->__add_char(']'); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3696 | ++__first; |
| 3697 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3698 | __first = __parse_follow_list(__first, __last, __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3699 | if (__first == __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3700 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3701 | if (*__first == '-') |
| 3702 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3703 | __ml->__add_char('-'); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3704 | ++__first; |
| 3705 | } |
| 3706 | if (__first == __last || *__first != ']') |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3707 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3708 | ++__first; |
| 3709 | } |
| 3710 | return __first; |
| 3711 | } |
| 3712 | |
| 3713 | template <class _CharT, class _Traits> |
| 3714 | template <class _ForwardIterator> |
| 3715 | _ForwardIterator |
| 3716 | basic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3717 | _ForwardIterator __last, |
| 3718 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3719 | { |
| 3720 | if (__first != __last) |
| 3721 | { |
| 3722 | while (true) |
| 3723 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3724 | _ForwardIterator __temp = __parse_expression_term(__first, __last, |
| 3725 | __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3726 | if (__temp == __first) |
| 3727 | break; |
| 3728 | __first = __temp; |
| 3729 | } |
| 3730 | } |
| 3731 | return __first; |
| 3732 | } |
| 3733 | |
| 3734 | template <class _CharT, class _Traits> |
| 3735 | template <class _ForwardIterator> |
| 3736 | _ForwardIterator |
| 3737 | basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3738 | _ForwardIterator __last, |
| 3739 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3740 | { |
| 3741 | if (__first != __last && *__first != ']') |
| 3742 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3743 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3744 | basic_string<_CharT> __start_range; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3745 | if (__temp != __last && *__first == '[') |
| 3746 | { |
| 3747 | if (*__temp == '=') |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3748 | return __parse_equivalence_class(++__temp, __last, __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3749 | else if (*__temp == ':') |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3750 | return __parse_character_class(++__temp, __last, __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3751 | else if (*__temp == '.') |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3752 | __first = __parse_collating_symbol(++__temp, __last, __start_range); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3753 | } |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3754 | unsigned __grammar = __flags_ & 0x1F0; |
| 3755 | if (__start_range.empty()) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3756 | { |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3757 | if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') |
| 3758 | { |
| 3759 | if (__grammar == ECMAScript) |
| 3760 | __first = __parse_class_escape(++__first, __last, __start_range, __ml); |
| 3761 | else |
| 3762 | __first = __parse_awk_escape(++__first, __last, &__start_range); |
| 3763 | } |
| 3764 | else |
| 3765 | { |
| 3766 | __start_range = *__first; |
| 3767 | ++__first; |
| 3768 | } |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3769 | } |
| 3770 | if (__first != __last && *__first != ']') |
| 3771 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3772 | __temp = _VSTD::next(__first); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3773 | if (__temp != __last && *__first == '-' && *__temp != ']') |
| 3774 | { |
| 3775 | // parse a range |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3776 | basic_string<_CharT> __end_range; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3777 | __first = __temp; |
| 3778 | ++__temp; |
| 3779 | if (__temp != __last && *__first == '[' && *__temp == '.') |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3780 | __first = __parse_collating_symbol(++__temp, __last, __end_range); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3781 | else |
| 3782 | { |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3783 | if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') |
| 3784 | { |
| 3785 | if (__grammar == ECMAScript) |
| 3786 | __first = __parse_class_escape(++__first, __last, |
| 3787 | __end_range, __ml); |
| 3788 | else |
| 3789 | __first = __parse_awk_escape(++__first, __last, |
| 3790 | &__end_range); |
| 3791 | } |
| 3792 | else |
| 3793 | { |
| 3794 | __end_range = *__first; |
| 3795 | ++__first; |
| 3796 | } |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3797 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3798 | __ml->__add_range(_VSTD::move(__start_range), _VSTD::move(__end_range)); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3799 | } |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3800 | else if (!__start_range.empty()) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3801 | { |
| 3802 | if (__start_range.size() == 1) |
| 3803 | __ml->__add_char(__start_range[0]); |
| 3804 | else |
| 3805 | __ml->__add_digraph(__start_range[0], __start_range[1]); |
| 3806 | } |
| 3807 | } |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3808 | else if (!__start_range.empty()) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3809 | { |
| 3810 | if (__start_range.size() == 1) |
| 3811 | __ml->__add_char(__start_range[0]); |
| 3812 | else |
| 3813 | __ml->__add_digraph(__start_range[0], __start_range[1]); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3814 | } |
| 3815 | } |
| 3816 | return __first; |
| 3817 | } |
| 3818 | |
| 3819 | template <class _CharT, class _Traits> |
| 3820 | template <class _ForwardIterator> |
| 3821 | _ForwardIterator |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3822 | basic_regex<_CharT, _Traits>::__parse_class_escape(_ForwardIterator __first, |
| 3823 | _ForwardIterator __last, |
| 3824 | basic_string<_CharT>& __str, |
| 3825 | __bracket_expression<_CharT, _Traits>* __ml) |
| 3826 | { |
| 3827 | if (__first == __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3828 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3829 | switch (*__first) |
| 3830 | { |
| 3831 | case 0: |
| 3832 | __str = *__first; |
| 3833 | return ++__first; |
| 3834 | case 'b': |
| 3835 | __str = _CharT(8); |
| 3836 | return ++__first; |
| 3837 | case 'd': |
| 3838 | __ml->__add_class(ctype_base::digit); |
| 3839 | return ++__first; |
| 3840 | case 'D': |
| 3841 | __ml->__add_neg_class(ctype_base::digit); |
| 3842 | return ++__first; |
| 3843 | case 's': |
| 3844 | __ml->__add_class(ctype_base::space); |
| 3845 | return ++__first; |
| 3846 | case 'S': |
| 3847 | __ml->__add_neg_class(ctype_base::space); |
| 3848 | return ++__first; |
| 3849 | case 'w': |
| 3850 | __ml->__add_class(ctype_base::alnum); |
| 3851 | __ml->__add_char('_'); |
| 3852 | return ++__first; |
| 3853 | case 'W': |
| 3854 | __ml->__add_neg_class(ctype_base::alnum); |
| 3855 | __ml->__add_neg_char('_'); |
| 3856 | return ++__first; |
| 3857 | } |
| 3858 | __first = __parse_character_escape(__first, __last, &__str); |
| 3859 | return __first; |
| 3860 | } |
| 3861 | |
| 3862 | template <class _CharT, class _Traits> |
| 3863 | template <class _ForwardIterator> |
| 3864 | _ForwardIterator |
| 3865 | basic_regex<_CharT, _Traits>::__parse_awk_escape(_ForwardIterator __first, |
| 3866 | _ForwardIterator __last, |
| 3867 | basic_string<_CharT>* __str) |
| 3868 | { |
| 3869 | if (__first == __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3870 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3871 | switch (*__first) |
| 3872 | { |
| 3873 | case '\\': |
| 3874 | case '"': |
| 3875 | case '/': |
| 3876 | if (__str) |
| 3877 | *__str = *__first; |
| 3878 | else |
| 3879 | __push_char(*__first); |
| 3880 | return ++__first; |
| 3881 | case 'a': |
| 3882 | if (__str) |
| 3883 | *__str = _CharT(7); |
| 3884 | else |
| 3885 | __push_char(_CharT(7)); |
| 3886 | return ++__first; |
| 3887 | case 'b': |
| 3888 | if (__str) |
| 3889 | *__str = _CharT(8); |
| 3890 | else |
| 3891 | __push_char(_CharT(8)); |
| 3892 | return ++__first; |
| 3893 | case 'f': |
| 3894 | if (__str) |
| 3895 | *__str = _CharT(0xC); |
| 3896 | else |
| 3897 | __push_char(_CharT(0xC)); |
| 3898 | return ++__first; |
| 3899 | case 'n': |
| 3900 | if (__str) |
| 3901 | *__str = _CharT(0xA); |
| 3902 | else |
| 3903 | __push_char(_CharT(0xA)); |
| 3904 | return ++__first; |
| 3905 | case 'r': |
| 3906 | if (__str) |
| 3907 | *__str = _CharT(0xD); |
| 3908 | else |
| 3909 | __push_char(_CharT(0xD)); |
| 3910 | return ++__first; |
| 3911 | case 't': |
| 3912 | if (__str) |
| 3913 | *__str = _CharT(0x9); |
| 3914 | else |
| 3915 | __push_char(_CharT(0x9)); |
| 3916 | return ++__first; |
| 3917 | case 'v': |
| 3918 | if (__str) |
| 3919 | *__str = _CharT(0xB); |
| 3920 | else |
| 3921 | __push_char(_CharT(0xB)); |
| 3922 | return ++__first; |
| 3923 | } |
| 3924 | if ('0' <= *__first && *__first <= '7') |
| 3925 | { |
| 3926 | unsigned __val = *__first - '0'; |
| 3927 | if (++__first != __last && ('0' <= *__first && *__first <= '7')) |
| 3928 | { |
| 3929 | __val = 8 * __val + *__first - '0'; |
| 3930 | if (++__first != __last && ('0' <= *__first && *__first <= '7')) |
Howard Hinnant | dbc8cf0 | 2013-07-02 17:43:31 +0000 | [diff] [blame] | 3931 | __val = 8 * __val + *__first++ - '0'; |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3932 | } |
| 3933 | if (__str) |
| 3934 | *__str = _CharT(__val); |
| 3935 | else |
| 3936 | __push_char(_CharT(__val)); |
| 3937 | } |
| 3938 | else |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3939 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3940 | return __first; |
| 3941 | } |
| 3942 | |
| 3943 | template <class _CharT, class _Traits> |
| 3944 | template <class _ForwardIterator> |
| 3945 | _ForwardIterator |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3946 | basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3947 | _ForwardIterator __last, |
| 3948 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3949 | { |
| 3950 | // Found [= |
| 3951 | // This means =] must exist |
| 3952 | value_type _Equal_close[2] = {'=', ']'}; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3953 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Equal_close, |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3954 | _Equal_close+2); |
| 3955 | if (__temp == __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3956 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3957 | // [__first, __temp) contains all text in [= ... =] |
| 3958 | typedef typename _Traits::string_type string_type; |
| 3959 | string_type __collate_name = |
| 3960 | __traits_.lookup_collatename(__first, __temp); |
| 3961 | if (__collate_name.empty()) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3962 | __throw_regex_error<regex_constants::error_collate>(); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3963 | string_type __equiv_name = |
| 3964 | __traits_.transform_primary(__collate_name.begin(), |
| 3965 | __collate_name.end()); |
| 3966 | if (!__equiv_name.empty()) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3967 | __ml->__add_equivalence(__equiv_name); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3968 | else |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3969 | { |
| 3970 | switch (__collate_name.size()) |
| 3971 | { |
| 3972 | case 1: |
| 3973 | __ml->__add_char(__collate_name[0]); |
| 3974 | break; |
| 3975 | case 2: |
| 3976 | __ml->__add_digraph(__collate_name[0], __collate_name[1]); |
| 3977 | break; |
| 3978 | default: |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3979 | __throw_regex_error<regex_constants::error_collate>(); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3980 | } |
| 3981 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3982 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3983 | return __first; |
| 3984 | } |
| 3985 | |
| 3986 | template <class _CharT, class _Traits> |
| 3987 | template <class _ForwardIterator> |
| 3988 | _ForwardIterator |
| 3989 | basic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3990 | _ForwardIterator __last, |
| 3991 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3992 | { |
| 3993 | // Found [: |
| 3994 | // This means :] must exist |
| 3995 | value_type _Colon_close[2] = {':', ']'}; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3996 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Colon_close, |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3997 | _Colon_close+2); |
| 3998 | if (__temp == __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3999 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4000 | // [__first, __temp) contains all text in [: ... :] |
| 4001 | typedef typename _Traits::char_class_type char_class_type; |
| 4002 | char_class_type __class_type = |
| 4003 | __traits_.lookup_classname(__first, __temp, __flags_ & icase); |
| 4004 | if (__class_type == 0) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4005 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4006 | __ml->__add_class(__class_type); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4007 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4008 | return __first; |
| 4009 | } |
| 4010 | |
| 4011 | template <class _CharT, class _Traits> |
| 4012 | template <class _ForwardIterator> |
| 4013 | _ForwardIterator |
| 4014 | basic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4015 | _ForwardIterator __last, |
| 4016 | basic_string<_CharT>& __col_sym) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4017 | { |
| 4018 | // Found [. |
| 4019 | // This means .] must exist |
| 4020 | value_type _Dot_close[2] = {'.', ']'}; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4021 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Dot_close, |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4022 | _Dot_close+2); |
| 4023 | if (__temp == __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4024 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4025 | // [__first, __temp) contains all text in [. ... .] |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4026 | __col_sym = __traits_.lookup_collatename(__first, __temp); |
| 4027 | switch (__col_sym.size()) |
| 4028 | { |
| 4029 | case 1: |
| 4030 | case 2: |
| 4031 | break; |
| 4032 | default: |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4033 | __throw_regex_error<regex_constants::error_collate>(); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4034 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4035 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4036 | return __first; |
| 4037 | } |
| 4038 | |
| 4039 | template <class _CharT, class _Traits> |
| 4040 | template <class _ForwardIterator> |
| 4041 | _ForwardIterator |
| 4042 | basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first, |
| 4043 | _ForwardIterator __last, |
| 4044 | int& __c) |
| 4045 | { |
Marshall Clow | 97f50f6 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4046 | if (__first != __last ) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4047 | { |
Marshall Clow | 97f50f6 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4048 | int __val = __traits_.value(*__first, 10); |
| 4049 | if ( __val != -1 ) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4050 | { |
Marshall Clow | 97f50f6 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4051 | __c = __val; |
| 4052 | for (++__first; |
| 4053 | __first != __last && ( __val = __traits_.value(*__first, 10)) != -1; |
| 4054 | ++__first) |
| 4055 | { |
| 4056 | __c *= 10; |
| 4057 | __c += __val; |
| 4058 | } |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4059 | } |
| 4060 | } |
| 4061 | return __first; |
| 4062 | } |
| 4063 | |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4064 | template <class _CharT, class _Traits> |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4065 | template <class _ForwardIterator> |
| 4066 | _ForwardIterator |
| 4067 | basic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first, |
| 4068 | _ForwardIterator __last) |
| 4069 | { |
| 4070 | __owns_one_state<_CharT>* __sa = __end_; |
| 4071 | _ForwardIterator __temp = __parse_alternative(__first, __last); |
| 4072 | if (__temp == __first) |
| 4073 | __push_empty(); |
| 4074 | __first = __temp; |
| 4075 | while (__first != __last && *__first == '|') |
| 4076 | { |
| 4077 | __owns_one_state<_CharT>* __sb = __end_; |
| 4078 | __temp = __parse_alternative(++__first, __last); |
| 4079 | if (__temp == __first) |
| 4080 | __push_empty(); |
| 4081 | __push_alternation(__sa, __sb); |
| 4082 | __first = __temp; |
| 4083 | } |
| 4084 | return __first; |
| 4085 | } |
| 4086 | |
| 4087 | template <class _CharT, class _Traits> |
| 4088 | template <class _ForwardIterator> |
| 4089 | _ForwardIterator |
| 4090 | basic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first, |
| 4091 | _ForwardIterator __last) |
| 4092 | { |
| 4093 | while (true) |
| 4094 | { |
| 4095 | _ForwardIterator __temp = __parse_term(__first, __last); |
| 4096 | if (__temp == __first) |
| 4097 | break; |
| 4098 | __first = __temp; |
| 4099 | } |
| 4100 | return __first; |
| 4101 | } |
| 4102 | |
| 4103 | template <class _CharT, class _Traits> |
| 4104 | template <class _ForwardIterator> |
| 4105 | _ForwardIterator |
| 4106 | basic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first, |
| 4107 | _ForwardIterator __last) |
| 4108 | { |
| 4109 | _ForwardIterator __temp = __parse_assertion(__first, __last); |
| 4110 | if (__temp == __first) |
| 4111 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4112 | __owns_one_state<_CharT>* __e = __end_; |
| 4113 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4114 | __temp = __parse_atom(__first, __last); |
| 4115 | if (__temp != __first) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4116 | __first = __parse_ERE_dupl_symbol(__temp, __last, __e, |
| 4117 | __mexp_begin+1, __marked_count_+1); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4118 | } |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4119 | else |
| 4120 | __first = __temp; |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4121 | return __first; |
| 4122 | } |
| 4123 | |
| 4124 | template <class _CharT, class _Traits> |
| 4125 | template <class _ForwardIterator> |
| 4126 | _ForwardIterator |
| 4127 | basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first, |
| 4128 | _ForwardIterator __last) |
| 4129 | { |
| 4130 | if (__first != __last) |
| 4131 | { |
| 4132 | switch (*__first) |
| 4133 | { |
| 4134 | case '^': |
| 4135 | __push_l_anchor(); |
| 4136 | ++__first; |
| 4137 | break; |
| 4138 | case '$': |
| 4139 | __push_r_anchor(); |
| 4140 | ++__first; |
| 4141 | break; |
| 4142 | case '\\': |
| 4143 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4144 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4145 | if (__temp != __last) |
| 4146 | { |
| 4147 | if (*__temp == 'b') |
| 4148 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4149 | __push_word_boundary(false); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4150 | __first = ++__temp; |
| 4151 | } |
| 4152 | else if (*__temp == 'B') |
| 4153 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4154 | __push_word_boundary(true); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4155 | __first = ++__temp; |
| 4156 | } |
| 4157 | } |
| 4158 | } |
| 4159 | break; |
| 4160 | case '(': |
| 4161 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4162 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4163 | if (__temp != __last && *__temp == '?') |
| 4164 | { |
| 4165 | if (++__temp != __last) |
| 4166 | { |
| 4167 | switch (*__temp) |
| 4168 | { |
| 4169 | case '=': |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4170 | { |
| 4171 | basic_regex __exp; |
| 4172 | __exp.__flags_ = __flags_; |
| 4173 | __temp = __exp.__parse(++__temp, __last); |
Howard Hinnant | cd59acc | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 4174 | unsigned __mexp = __exp.__marked_count_; |
| 4175 | __push_lookahead(_VSTD::move(__exp), false, __marked_count_); |
| 4176 | __marked_count_ += __mexp; |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4177 | if (__temp == __last || *__temp != ')') |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4178 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4179 | __first = ++__temp; |
| 4180 | } |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4181 | break; |
| 4182 | case '!': |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4183 | { |
| 4184 | basic_regex __exp; |
| 4185 | __exp.__flags_ = __flags_; |
| 4186 | __temp = __exp.__parse(++__temp, __last); |
Howard Hinnant | cd59acc | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 4187 | unsigned __mexp = __exp.__marked_count_; |
| 4188 | __push_lookahead(_VSTD::move(__exp), true, __marked_count_); |
| 4189 | __marked_count_ += __mexp; |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4190 | if (__temp == __last || *__temp != ')') |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4191 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4192 | __first = ++__temp; |
| 4193 | } |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4194 | break; |
| 4195 | } |
| 4196 | } |
| 4197 | } |
| 4198 | } |
| 4199 | break; |
| 4200 | } |
| 4201 | } |
| 4202 | return __first; |
| 4203 | } |
| 4204 | |
| 4205 | template <class _CharT, class _Traits> |
| 4206 | template <class _ForwardIterator> |
| 4207 | _ForwardIterator |
| 4208 | basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first, |
| 4209 | _ForwardIterator __last) |
| 4210 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4211 | if (__first != __last) |
| 4212 | { |
| 4213 | switch (*__first) |
| 4214 | { |
| 4215 | case '.': |
| 4216 | __push_match_any_but_newline(); |
| 4217 | ++__first; |
| 4218 | break; |
| 4219 | case '\\': |
| 4220 | __first = __parse_atom_escape(__first, __last); |
| 4221 | break; |
| 4222 | case '[': |
| 4223 | __first = __parse_bracket_expression(__first, __last); |
| 4224 | break; |
| 4225 | case '(': |
| 4226 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4227 | ++__first; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4228 | if (__first == __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4229 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4230 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4231 | if (__temp != __last && *__first == '?' && *__temp == ':') |
| 4232 | { |
| 4233 | ++__open_count_; |
| 4234 | __first = __parse_ecma_exp(++__temp, __last); |
| 4235 | if (__first == __last || *__first != ')') |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4236 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4237 | --__open_count_; |
| 4238 | ++__first; |
| 4239 | } |
| 4240 | else |
| 4241 | { |
| 4242 | __push_begin_marked_subexpression(); |
| 4243 | unsigned __temp_count = __marked_count_; |
| 4244 | ++__open_count_; |
| 4245 | __first = __parse_ecma_exp(__first, __last); |
| 4246 | if (__first == __last || *__first != ')') |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4247 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4248 | __push_end_marked_subexpression(__temp_count); |
| 4249 | --__open_count_; |
| 4250 | ++__first; |
| 4251 | } |
| 4252 | } |
| 4253 | break; |
Marshall Clow | 568bd02 | 2015-07-23 18:27:51 +0000 | [diff] [blame] | 4254 | case '*': |
| 4255 | case '+': |
| 4256 | case '?': |
| 4257 | case '{': |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4258 | __throw_regex_error<regex_constants::error_badrepeat>(); |
Marshall Clow | 568bd02 | 2015-07-23 18:27:51 +0000 | [diff] [blame] | 4259 | break; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4260 | default: |
| 4261 | __first = __parse_pattern_character(__first, __last); |
| 4262 | break; |
| 4263 | } |
| 4264 | } |
| 4265 | return __first; |
| 4266 | } |
| 4267 | |
| 4268 | template <class _CharT, class _Traits> |
| 4269 | template <class _ForwardIterator> |
| 4270 | _ForwardIterator |
| 4271 | basic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first, |
| 4272 | _ForwardIterator __last) |
| 4273 | { |
| 4274 | if (__first != __last && *__first == '\\') |
| 4275 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4276 | _ForwardIterator __t1 = _VSTD::next(__first); |
Marshall Clow | 685cdca | 2016-01-19 00:50:37 +0000 | [diff] [blame] | 4277 | if (__t1 == __last) |
| 4278 | __throw_regex_error<regex_constants::error_escape>(); |
| 4279 | |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4280 | _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last); |
| 4281 | if (__t2 != __t1) |
| 4282 | __first = __t2; |
| 4283 | else |
| 4284 | { |
| 4285 | __t2 = __parse_character_class_escape(__t1, __last); |
| 4286 | if (__t2 != __t1) |
| 4287 | __first = __t2; |
| 4288 | else |
| 4289 | { |
| 4290 | __t2 = __parse_character_escape(__t1, __last); |
| 4291 | if (__t2 != __t1) |
| 4292 | __first = __t2; |
| 4293 | } |
| 4294 | } |
| 4295 | } |
| 4296 | return __first; |
| 4297 | } |
| 4298 | |
| 4299 | template <class _CharT, class _Traits> |
| 4300 | template <class _ForwardIterator> |
| 4301 | _ForwardIterator |
| 4302 | basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first, |
| 4303 | _ForwardIterator __last) |
| 4304 | { |
| 4305 | if (__first != __last) |
| 4306 | { |
| 4307 | if (*__first == '0') |
| 4308 | { |
| 4309 | __push_char(_CharT()); |
| 4310 | ++__first; |
| 4311 | } |
| 4312 | else if ('1' <= *__first && *__first <= '9') |
| 4313 | { |
| 4314 | unsigned __v = *__first - '0'; |
| 4315 | for (++__first; '0' <= *__first && *__first <= '9'; ++__first) |
| 4316 | __v = 10 * __v + *__first - '0'; |
| 4317 | if (__v > mark_count()) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4318 | __throw_regex_error<regex_constants::error_backref>(); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4319 | __push_back_ref(__v); |
| 4320 | } |
| 4321 | } |
| 4322 | return __first; |
| 4323 | } |
| 4324 | |
| 4325 | template <class _CharT, class _Traits> |
| 4326 | template <class _ForwardIterator> |
| 4327 | _ForwardIterator |
| 4328 | basic_regex<_CharT, _Traits>::__parse_character_class_escape(_ForwardIterator __first, |
| 4329 | _ForwardIterator __last) |
| 4330 | { |
| 4331 | if (__first != __last) |
| 4332 | { |
| 4333 | __bracket_expression<_CharT, _Traits>* __ml; |
| 4334 | switch (*__first) |
| 4335 | { |
| 4336 | case 'd': |
| 4337 | __ml = __start_matching_list(false); |
| 4338 | __ml->__add_class(ctype_base::digit); |
| 4339 | ++__first; |
| 4340 | break; |
| 4341 | case 'D': |
| 4342 | __ml = __start_matching_list(true); |
| 4343 | __ml->__add_class(ctype_base::digit); |
| 4344 | ++__first; |
| 4345 | break; |
| 4346 | case 's': |
| 4347 | __ml = __start_matching_list(false); |
| 4348 | __ml->__add_class(ctype_base::space); |
| 4349 | ++__first; |
| 4350 | break; |
| 4351 | case 'S': |
| 4352 | __ml = __start_matching_list(true); |
| 4353 | __ml->__add_class(ctype_base::space); |
| 4354 | ++__first; |
| 4355 | break; |
| 4356 | case 'w': |
| 4357 | __ml = __start_matching_list(false); |
| 4358 | __ml->__add_class(ctype_base::alnum); |
| 4359 | __ml->__add_char('_'); |
| 4360 | ++__first; |
| 4361 | break; |
| 4362 | case 'W': |
| 4363 | __ml = __start_matching_list(true); |
| 4364 | __ml->__add_class(ctype_base::alnum); |
| 4365 | __ml->__add_char('_'); |
| 4366 | ++__first; |
| 4367 | break; |
| 4368 | } |
| 4369 | } |
| 4370 | return __first; |
| 4371 | } |
| 4372 | |
| 4373 | template <class _CharT, class _Traits> |
| 4374 | template <class _ForwardIterator> |
| 4375 | _ForwardIterator |
| 4376 | basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first, |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4377 | _ForwardIterator __last, |
| 4378 | basic_string<_CharT>* __str) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4379 | { |
| 4380 | if (__first != __last) |
| 4381 | { |
| 4382 | _ForwardIterator __t; |
| 4383 | unsigned __sum = 0; |
| 4384 | int __hd; |
| 4385 | switch (*__first) |
| 4386 | { |
| 4387 | case 'f': |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4388 | if (__str) |
| 4389 | *__str = _CharT(0xC); |
| 4390 | else |
| 4391 | __push_char(_CharT(0xC)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4392 | ++__first; |
| 4393 | break; |
| 4394 | case 'n': |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4395 | if (__str) |
| 4396 | *__str = _CharT(0xA); |
| 4397 | else |
| 4398 | __push_char(_CharT(0xA)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4399 | ++__first; |
| 4400 | break; |
| 4401 | case 'r': |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4402 | if (__str) |
| 4403 | *__str = _CharT(0xD); |
| 4404 | else |
| 4405 | __push_char(_CharT(0xD)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4406 | ++__first; |
| 4407 | break; |
| 4408 | case 't': |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4409 | if (__str) |
| 4410 | *__str = _CharT(0x9); |
| 4411 | else |
| 4412 | __push_char(_CharT(0x9)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4413 | ++__first; |
| 4414 | break; |
| 4415 | case 'v': |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4416 | if (__str) |
| 4417 | *__str = _CharT(0xB); |
| 4418 | else |
| 4419 | __push_char(_CharT(0xB)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4420 | ++__first; |
| 4421 | break; |
| 4422 | case 'c': |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4423 | if ((__t = _VSTD::next(__first)) != __last) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4424 | { |
Howard Hinnant | 1e1d051 | 2013-07-15 18:21:11 +0000 | [diff] [blame] | 4425 | if (('A' <= *__t && *__t <= 'Z') || |
| 4426 | ('a' <= *__t && *__t <= 'z')) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4427 | { |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4428 | if (__str) |
| 4429 | *__str = _CharT(*__t % 32); |
| 4430 | else |
| 4431 | __push_char(_CharT(*__t % 32)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4432 | __first = ++__t; |
| 4433 | } |
Howard Hinnant | 1e1d051 | 2013-07-15 18:21:11 +0000 | [diff] [blame] | 4434 | else |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4435 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4436 | } |
Howard Hinnant | 1e1d051 | 2013-07-15 18:21:11 +0000 | [diff] [blame] | 4437 | else |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4438 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4439 | break; |
| 4440 | case 'u': |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4441 | ++__first; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4442 | if (__first == __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4443 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4444 | __hd = __traits_.value(*__first, 16); |
| 4445 | if (__hd == -1) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4446 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4447 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4448 | ++__first; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4449 | if (__first == __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4450 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4451 | __hd = __traits_.value(*__first, 16); |
| 4452 | if (__hd == -1) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4453 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4454 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4455 | // drop through |
| 4456 | case 'x': |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4457 | ++__first; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4458 | if (__first == __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4459 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4460 | __hd = __traits_.value(*__first, 16); |
| 4461 | if (__hd == -1) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4462 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4463 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4464 | ++__first; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4465 | if (__first == __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4466 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4467 | __hd = __traits_.value(*__first, 16); |
| 4468 | if (__hd == -1) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4469 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4470 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4471 | if (__str) |
| 4472 | *__str = _CharT(__sum); |
| 4473 | else |
| 4474 | __push_char(_CharT(__sum)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4475 | ++__first; |
| 4476 | break; |
Marshall Clow | 6b7e692 | 2014-05-21 16:29:50 +0000 | [diff] [blame] | 4477 | case '0': |
| 4478 | if (__str) |
| 4479 | *__str = _CharT(0); |
| 4480 | else |
| 4481 | __push_char(_CharT(0)); |
| 4482 | ++__first; |
| 4483 | break; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4484 | default: |
| 4485 | if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum)) |
| 4486 | { |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4487 | if (__str) |
| 4488 | *__str = *__first; |
| 4489 | else |
| 4490 | __push_char(*__first); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4491 | ++__first; |
| 4492 | } |
Howard Hinnant | 918f2a8 | 2013-06-28 18:57:30 +0000 | [diff] [blame] | 4493 | else |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4494 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4495 | break; |
| 4496 | } |
| 4497 | } |
| 4498 | return __first; |
| 4499 | } |
| 4500 | |
| 4501 | template <class _CharT, class _Traits> |
| 4502 | template <class _ForwardIterator> |
| 4503 | _ForwardIterator |
| 4504 | basic_regex<_CharT, _Traits>::__parse_pattern_character(_ForwardIterator __first, |
| 4505 | _ForwardIterator __last) |
| 4506 | { |
| 4507 | if (__first != __last) |
| 4508 | { |
| 4509 | switch (*__first) |
| 4510 | { |
| 4511 | case '^': |
| 4512 | case '$': |
| 4513 | case '\\': |
| 4514 | case '.': |
| 4515 | case '*': |
| 4516 | case '+': |
| 4517 | case '?': |
| 4518 | case '(': |
| 4519 | case ')': |
| 4520 | case '[': |
| 4521 | case ']': |
| 4522 | case '{': |
| 4523 | case '}': |
| 4524 | case '|': |
| 4525 | break; |
| 4526 | default: |
| 4527 | __push_char(*__first); |
| 4528 | ++__first; |
| 4529 | break; |
| 4530 | } |
| 4531 | } |
| 4532 | return __first; |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4533 | } |
| 4534 | |
| 4535 | template <class _CharT, class _Traits> |
Howard Hinnant | 856846b | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4536 | template <class _ForwardIterator> |
| 4537 | _ForwardIterator |
| 4538 | basic_regex<_CharT, _Traits>::__parse_grep(_ForwardIterator __first, |
| 4539 | _ForwardIterator __last) |
| 4540 | { |
| 4541 | __owns_one_state<_CharT>* __sa = __end_; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4542 | _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | 856846b | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4543 | if (__t1 != __first) |
| 4544 | __parse_basic_reg_exp(__first, __t1); |
| 4545 | else |
| 4546 | __push_empty(); |
| 4547 | __first = __t1; |
| 4548 | if (__first != __last) |
| 4549 | ++__first; |
| 4550 | while (__first != __last) |
| 4551 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4552 | __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | 856846b | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4553 | __owns_one_state<_CharT>* __sb = __end_; |
| 4554 | if (__t1 != __first) |
| 4555 | __parse_basic_reg_exp(__first, __t1); |
| 4556 | else |
| 4557 | __push_empty(); |
| 4558 | __push_alternation(__sa, __sb); |
| 4559 | __first = __t1; |
| 4560 | if (__first != __last) |
| 4561 | ++__first; |
| 4562 | } |
| 4563 | return __first; |
| 4564 | } |
| 4565 | |
| 4566 | template <class _CharT, class _Traits> |
| 4567 | template <class _ForwardIterator> |
| 4568 | _ForwardIterator |
| 4569 | basic_regex<_CharT, _Traits>::__parse_egrep(_ForwardIterator __first, |
| 4570 | _ForwardIterator __last) |
| 4571 | { |
| 4572 | __owns_one_state<_CharT>* __sa = __end_; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4573 | _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | 856846b | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4574 | if (__t1 != __first) |
| 4575 | __parse_extended_reg_exp(__first, __t1); |
| 4576 | else |
| 4577 | __push_empty(); |
| 4578 | __first = __t1; |
| 4579 | if (__first != __last) |
| 4580 | ++__first; |
| 4581 | while (__first != __last) |
| 4582 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4583 | __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | 856846b | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4584 | __owns_one_state<_CharT>* __sb = __end_; |
| 4585 | if (__t1 != __first) |
| 4586 | __parse_extended_reg_exp(__first, __t1); |
| 4587 | else |
| 4588 | __push_empty(); |
| 4589 | __push_alternation(__sa, __sb); |
| 4590 | __first = __t1; |
| 4591 | if (__first != __last) |
| 4592 | ++__first; |
| 4593 | } |
| 4594 | return __first; |
| 4595 | } |
| 4596 | |
| 4597 | template <class _CharT, class _Traits> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4598 | void |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4599 | basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max, |
| 4600 | __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end, |
| 4601 | bool __greedy) |
| 4602 | { |
| 4603 | unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first())); |
| 4604 | __end_->first() = nullptr; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4605 | unique_ptr<__loop<_CharT> > __e2(new __loop<_CharT>(__loop_count_, |
| 4606 | __s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy, |
| 4607 | __min, __max)); |
| 4608 | __s->first() = nullptr; |
| 4609 | __e1.release(); |
| 4610 | __end_->first() = new __repeat_one_loop<_CharT>(__e2.get()); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4611 | __end_ = __e2->second(); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4612 | __s->first() = __e2.release(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4613 | ++__loop_count_; |
| 4614 | } |
| 4615 | |
| 4616 | template <class _CharT, class _Traits> |
| 4617 | void |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4618 | basic_regex<_CharT, _Traits>::__push_char(value_type __c) |
| 4619 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4620 | if (flags() & icase) |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4621 | __end_->first() = new __match_char_icase<_CharT, _Traits> |
| 4622 | (__traits_, __c, __end_->first()); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4623 | else if (flags() & collate) |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4624 | __end_->first() = new __match_char_collate<_CharT, _Traits> |
| 4625 | (__traits_, __c, __end_->first()); |
| 4626 | else |
| 4627 | __end_->first() = new __match_char<_CharT>(__c, __end_->first()); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 4628 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4629 | } |
| 4630 | |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4631 | template <class _CharT, class _Traits> |
| 4632 | void |
| 4633 | basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression() |
| 4634 | { |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 4635 | if (!(__flags_ & nosubs)) |
| 4636 | { |
| 4637 | __end_->first() = |
| 4638 | new __begin_marked_subexpression<_CharT>(++__marked_count_, |
| 4639 | __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 | |
| 4644 | template <class _CharT, class _Traits> |
| 4645 | void |
| 4646 | basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub) |
| 4647 | { |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 4648 | if (!(__flags_ & nosubs)) |
| 4649 | { |
| 4650 | __end_->first() = |
| 4651 | new __end_marked_subexpression<_CharT>(__sub, __end_->first()); |
| 4652 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4653 | } |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4654 | } |
| 4655 | |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4656 | template <class _CharT, class _Traits> |
| 4657 | void |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 4658 | basic_regex<_CharT, _Traits>::__push_l_anchor() |
| 4659 | { |
| 4660 | __end_->first() = new __l_anchor<_CharT>(__end_->first()); |
| 4661 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4662 | } |
| 4663 | |
| 4664 | template <class _CharT, class _Traits> |
| 4665 | void |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4666 | basic_regex<_CharT, _Traits>::__push_r_anchor() |
| 4667 | { |
| 4668 | __end_->first() = new __r_anchor<_CharT>(__end_->first()); |
| 4669 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4670 | } |
| 4671 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4672 | template <class _CharT, class _Traits> |
| 4673 | void |
| 4674 | basic_regex<_CharT, _Traits>::__push_match_any() |
| 4675 | { |
| 4676 | __end_->first() = new __match_any<_CharT>(__end_->first()); |
| 4677 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4678 | } |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4679 | |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4680 | template <class _CharT, class _Traits> |
| 4681 | void |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4682 | basic_regex<_CharT, _Traits>::__push_match_any_but_newline() |
| 4683 | { |
| 4684 | __end_->first() = new __match_any_but_newline<_CharT>(__end_->first()); |
| 4685 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4686 | } |
| 4687 | |
| 4688 | template <class _CharT, class _Traits> |
| 4689 | void |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4690 | basic_regex<_CharT, _Traits>::__push_empty() |
| 4691 | { |
| 4692 | __end_->first() = new __empty_state<_CharT>(__end_->first()); |
| 4693 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4694 | } |
| 4695 | |
| 4696 | template <class _CharT, class _Traits> |
| 4697 | void |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4698 | basic_regex<_CharT, _Traits>::__push_word_boundary(bool __invert) |
| 4699 | { |
| 4700 | __end_->first() = new __word_boundary<_CharT, _Traits>(__traits_, __invert, |
| 4701 | __end_->first()); |
| 4702 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4703 | } |
| 4704 | |
| 4705 | template <class _CharT, class _Traits> |
| 4706 | void |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4707 | basic_regex<_CharT, _Traits>::__push_back_ref(int __i) |
| 4708 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4709 | if (flags() & icase) |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4710 | __end_->first() = new __back_ref_icase<_CharT, _Traits> |
| 4711 | (__traits_, __i, __end_->first()); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4712 | else if (flags() & collate) |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4713 | __end_->first() = new __back_ref_collate<_CharT, _Traits> |
| 4714 | (__traits_, __i, __end_->first()); |
| 4715 | else |
| 4716 | __end_->first() = new __back_ref<_CharT>(__i, __end_->first()); |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4717 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4718 | } |
| 4719 | |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4720 | template <class _CharT, class _Traits> |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 4721 | void |
| 4722 | basic_regex<_CharT, _Traits>::__push_alternation(__owns_one_state<_CharT>* __sa, |
| 4723 | __owns_one_state<_CharT>* __ea) |
| 4724 | { |
| 4725 | __sa->first() = new __alternate<_CharT>( |
| 4726 | static_cast<__owns_one_state<_CharT>*>(__sa->first()), |
| 4727 | static_cast<__owns_one_state<_CharT>*>(__ea->first())); |
| 4728 | __ea->first() = nullptr; |
| 4729 | __ea->first() = new __empty_state<_CharT>(__end_->first()); |
| 4730 | __end_->first() = nullptr; |
| 4731 | __end_->first() = new __empty_non_own_state<_CharT>(__ea->first()); |
| 4732 | __end_ = static_cast<__owns_one_state<_CharT>*>(__ea->first()); |
| 4733 | } |
| 4734 | |
| 4735 | template <class _CharT, class _Traits> |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4736 | __bracket_expression<_CharT, _Traits>* |
| 4737 | basic_regex<_CharT, _Traits>::__start_matching_list(bool __negate) |
| 4738 | { |
| 4739 | __bracket_expression<_CharT, _Traits>* __r = |
| 4740 | new __bracket_expression<_CharT, _Traits>(__traits_, __end_->first(), |
| 4741 | __negate, __flags_ & icase, |
| 4742 | __flags_ & collate); |
| 4743 | __end_->first() = __r; |
| 4744 | __end_ = __r; |
| 4745 | return __r; |
| 4746 | } |
| 4747 | |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4748 | template <class _CharT, class _Traits> |
| 4749 | void |
| 4750 | basic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp, |
Howard Hinnant | cd59acc | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 4751 | bool __invert, |
| 4752 | unsigned __mexp) |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4753 | { |
| 4754 | __end_->first() = new __lookahead<_CharT, _Traits>(__exp, __invert, |
Howard Hinnant | cd59acc | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 4755 | __end_->first(), __mexp); |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4756 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4757 | } |
| 4758 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 4759 | typedef basic_regex<char> regex; |
| 4760 | typedef basic_regex<wchar_t> wregex; |
| 4761 | |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4762 | // sub_match |
| 4763 | |
| 4764 | template <class _BidirectionalIterator> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 4765 | class _LIBCPP_TYPE_VIS_ONLY sub_match |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4766 | : public pair<_BidirectionalIterator, _BidirectionalIterator> |
| 4767 | { |
| 4768 | public: |
| 4769 | typedef _BidirectionalIterator iterator; |
| 4770 | typedef typename iterator_traits<iterator>::value_type value_type; |
| 4771 | typedef typename iterator_traits<iterator>::difference_type difference_type; |
| 4772 | typedef basic_string<value_type> string_type; |
| 4773 | |
| 4774 | bool matched; |
| 4775 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4776 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 4777 | _LIBCPP_CONSTEXPR sub_match() : matched() {} |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 4778 | |
| 4779 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4780 | difference_type length() const |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4781 | {return matched ? _VSTD::distance(this->first, this->second) : 0;} |
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 | string_type str() const |
| 4784 | {return matched ? string_type(this->first, this->second) : string_type();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4785 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4786 | operator string_type() const |
| 4787 | {return str();} |
| 4788 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4789 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4790 | int compare(const sub_match& __s) const |
| 4791 | {return str().compare(__s.str());} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4792 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4793 | int compare(const string_type& __s) const |
| 4794 | {return str().compare(__s);} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4795 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4796 | int compare(const value_type* __s) const |
| 4797 | {return str().compare(__s);} |
| 4798 | }; |
| 4799 | |
| 4800 | typedef sub_match<const char*> csub_match; |
| 4801 | typedef sub_match<const wchar_t*> wcsub_match; |
| 4802 | typedef sub_match<string::const_iterator> ssub_match; |
| 4803 | typedef sub_match<wstring::const_iterator> wssub_match; |
| 4804 | |
| 4805 | template <class _BiIter> |
| 4806 | inline _LIBCPP_INLINE_VISIBILITY |
| 4807 | bool |
| 4808 | operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4809 | { |
| 4810 | return __x.compare(__y) == 0; |
| 4811 | } |
| 4812 | |
| 4813 | template <class _BiIter> |
| 4814 | inline _LIBCPP_INLINE_VISIBILITY |
| 4815 | bool |
| 4816 | operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4817 | { |
| 4818 | return !(__x == __y); |
| 4819 | } |
| 4820 | |
| 4821 | template <class _BiIter> |
| 4822 | inline _LIBCPP_INLINE_VISIBILITY |
| 4823 | bool |
| 4824 | operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4825 | { |
| 4826 | return __x.compare(__y) < 0; |
| 4827 | } |
| 4828 | |
| 4829 | template <class _BiIter> |
| 4830 | inline _LIBCPP_INLINE_VISIBILITY |
| 4831 | bool |
| 4832 | operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4833 | { |
| 4834 | return !(__y < __x); |
| 4835 | } |
| 4836 | |
| 4837 | template <class _BiIter> |
| 4838 | inline _LIBCPP_INLINE_VISIBILITY |
| 4839 | bool |
| 4840 | operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4841 | { |
| 4842 | return !(__x < __y); |
| 4843 | } |
| 4844 | |
| 4845 | template <class _BiIter> |
| 4846 | inline _LIBCPP_INLINE_VISIBILITY |
| 4847 | bool |
| 4848 | operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4849 | { |
| 4850 | return __y < __x; |
| 4851 | } |
| 4852 | |
| 4853 | template <class _BiIter, class _ST, class _SA> |
| 4854 | inline _LIBCPP_INLINE_VISIBILITY |
| 4855 | bool |
| 4856 | operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4857 | const sub_match<_BiIter>& __y) |
| 4858 | { |
Marshall Clow | e3e7054 | 2014-12-15 23:57:56 +0000 | [diff] [blame] | 4859 | return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) == 0; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4860 | } |
| 4861 | |
| 4862 | template <class _BiIter, class _ST, class _SA> |
| 4863 | inline _LIBCPP_INLINE_VISIBILITY |
| 4864 | bool |
| 4865 | operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4866 | const sub_match<_BiIter>& __y) |
| 4867 | { |
| 4868 | return !(__x == __y); |
| 4869 | } |
| 4870 | |
| 4871 | template <class _BiIter, class _ST, class _SA> |
| 4872 | inline _LIBCPP_INLINE_VISIBILITY |
| 4873 | bool |
| 4874 | operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4875 | const sub_match<_BiIter>& __y) |
| 4876 | { |
Marshall Clow | e3e7054 | 2014-12-15 23:57:56 +0000 | [diff] [blame] | 4877 | return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) > 0; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4878 | } |
| 4879 | |
| 4880 | template <class _BiIter, class _ST, class _SA> |
| 4881 | inline _LIBCPP_INLINE_VISIBILITY |
| 4882 | bool |
| 4883 | operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4884 | const sub_match<_BiIter>& __y) |
| 4885 | { |
| 4886 | return __y < __x; |
| 4887 | } |
| 4888 | |
| 4889 | template <class _BiIter, class _ST, class _SA> |
| 4890 | inline _LIBCPP_INLINE_VISIBILITY |
| 4891 | bool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4892 | const sub_match<_BiIter>& __y) |
| 4893 | { |
| 4894 | return !(__x < __y); |
| 4895 | } |
| 4896 | |
| 4897 | template <class _BiIter, class _ST, class _SA> |
| 4898 | inline _LIBCPP_INLINE_VISIBILITY |
| 4899 | bool |
| 4900 | operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4901 | const sub_match<_BiIter>& __y) |
| 4902 | { |
| 4903 | return !(__y < __x); |
| 4904 | } |
| 4905 | |
| 4906 | template <class _BiIter, class _ST, class _SA> |
| 4907 | inline _LIBCPP_INLINE_VISIBILITY |
| 4908 | bool |
| 4909 | operator==(const sub_match<_BiIter>& __x, |
| 4910 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4911 | { |
Marshall Clow | e3e7054 | 2014-12-15 23:57:56 +0000 | [diff] [blame] | 4912 | return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) == 0; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4913 | } |
| 4914 | |
| 4915 | template <class _BiIter, class _ST, class _SA> |
| 4916 | inline _LIBCPP_INLINE_VISIBILITY |
| 4917 | bool |
| 4918 | operator!=(const sub_match<_BiIter>& __x, |
| 4919 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4920 | { |
| 4921 | return !(__x == __y); |
| 4922 | } |
| 4923 | |
| 4924 | template <class _BiIter, class _ST, class _SA> |
| 4925 | inline _LIBCPP_INLINE_VISIBILITY |
| 4926 | bool |
| 4927 | operator<(const sub_match<_BiIter>& __x, |
| 4928 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4929 | { |
Marshall Clow | e3e7054 | 2014-12-15 23:57:56 +0000 | [diff] [blame] | 4930 | return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) < 0; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4931 | } |
| 4932 | |
| 4933 | template <class _BiIter, class _ST, class _SA> |
| 4934 | inline _LIBCPP_INLINE_VISIBILITY |
| 4935 | bool operator>(const sub_match<_BiIter>& __x, |
| 4936 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4937 | { |
| 4938 | return __y < __x; |
| 4939 | } |
| 4940 | |
| 4941 | template <class _BiIter, class _ST, class _SA> |
| 4942 | inline _LIBCPP_INLINE_VISIBILITY |
| 4943 | bool |
| 4944 | operator>=(const sub_match<_BiIter>& __x, |
| 4945 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4946 | { |
| 4947 | return !(__x < __y); |
| 4948 | } |
| 4949 | |
| 4950 | template <class _BiIter, class _ST, class _SA> |
| 4951 | inline _LIBCPP_INLINE_VISIBILITY |
| 4952 | bool |
| 4953 | operator<=(const sub_match<_BiIter>& __x, |
| 4954 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4955 | { |
| 4956 | return !(__y < __x); |
| 4957 | } |
| 4958 | |
| 4959 | template <class _BiIter> |
| 4960 | inline _LIBCPP_INLINE_VISIBILITY |
| 4961 | bool |
| 4962 | operator==(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4963 | const sub_match<_BiIter>& __y) |
| 4964 | { |
| 4965 | return __y.compare(__x) == 0; |
| 4966 | } |
| 4967 | |
| 4968 | template <class _BiIter> |
| 4969 | inline _LIBCPP_INLINE_VISIBILITY |
| 4970 | bool |
| 4971 | operator!=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4972 | const sub_match<_BiIter>& __y) |
| 4973 | { |
| 4974 | return !(__x == __y); |
| 4975 | } |
| 4976 | |
| 4977 | template <class _BiIter> |
| 4978 | inline _LIBCPP_INLINE_VISIBILITY |
| 4979 | bool |
| 4980 | operator<(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4981 | const sub_match<_BiIter>& __y) |
| 4982 | { |
| 4983 | return __y.compare(__x) > 0; |
| 4984 | } |
| 4985 | |
| 4986 | template <class _BiIter> |
| 4987 | inline _LIBCPP_INLINE_VISIBILITY |
| 4988 | bool |
| 4989 | operator>(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4990 | const sub_match<_BiIter>& __y) |
| 4991 | { |
| 4992 | return __y < __x; |
| 4993 | } |
| 4994 | |
| 4995 | template <class _BiIter> |
| 4996 | inline _LIBCPP_INLINE_VISIBILITY |
| 4997 | bool |
| 4998 | operator>=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4999 | const sub_match<_BiIter>& __y) |
| 5000 | { |
| 5001 | return !(__x < __y); |
| 5002 | } |
| 5003 | |
| 5004 | template <class _BiIter> |
| 5005 | inline _LIBCPP_INLINE_VISIBILITY |
| 5006 | bool |
| 5007 | operator<=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5008 | const sub_match<_BiIter>& __y) |
| 5009 | { |
| 5010 | return !(__y < __x); |
| 5011 | } |
| 5012 | |
| 5013 | template <class _BiIter> |
| 5014 | inline _LIBCPP_INLINE_VISIBILITY |
| 5015 | bool |
| 5016 | operator==(const sub_match<_BiIter>& __x, |
| 5017 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5018 | { |
| 5019 | return __x.compare(__y) == 0; |
| 5020 | } |
| 5021 | |
| 5022 | template <class _BiIter> |
| 5023 | inline _LIBCPP_INLINE_VISIBILITY |
| 5024 | bool |
| 5025 | operator!=(const sub_match<_BiIter>& __x, |
| 5026 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5027 | { |
| 5028 | return !(__x == __y); |
| 5029 | } |
| 5030 | |
| 5031 | template <class _BiIter> |
| 5032 | inline _LIBCPP_INLINE_VISIBILITY |
| 5033 | bool |
| 5034 | operator<(const sub_match<_BiIter>& __x, |
| 5035 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5036 | { |
| 5037 | return __x.compare(__y) < 0; |
| 5038 | } |
| 5039 | |
| 5040 | template <class _BiIter> |
| 5041 | inline _LIBCPP_INLINE_VISIBILITY |
| 5042 | bool |
| 5043 | operator>(const sub_match<_BiIter>& __x, |
| 5044 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5045 | { |
| 5046 | return __y < __x; |
| 5047 | } |
| 5048 | |
| 5049 | template <class _BiIter> |
| 5050 | inline _LIBCPP_INLINE_VISIBILITY |
| 5051 | bool |
| 5052 | operator>=(const sub_match<_BiIter>& __x, |
| 5053 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5054 | { |
| 5055 | return !(__x < __y); |
| 5056 | } |
| 5057 | |
| 5058 | template <class _BiIter> |
| 5059 | inline _LIBCPP_INLINE_VISIBILITY |
| 5060 | bool |
| 5061 | operator<=(const sub_match<_BiIter>& __x, |
| 5062 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5063 | { |
| 5064 | return !(__y < __x); |
| 5065 | } |
| 5066 | |
| 5067 | template <class _BiIter> |
| 5068 | inline _LIBCPP_INLINE_VISIBILITY |
| 5069 | bool |
| 5070 | operator==(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5071 | const sub_match<_BiIter>& __y) |
| 5072 | { |
| 5073 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5074 | return __y.compare(string_type(1, __x)) == 0; |
| 5075 | } |
| 5076 | |
| 5077 | template <class _BiIter> |
| 5078 | inline _LIBCPP_INLINE_VISIBILITY |
| 5079 | bool |
| 5080 | operator!=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5081 | const sub_match<_BiIter>& __y) |
| 5082 | { |
| 5083 | return !(__x == __y); |
| 5084 | } |
| 5085 | |
| 5086 | template <class _BiIter> |
| 5087 | inline _LIBCPP_INLINE_VISIBILITY |
| 5088 | bool |
| 5089 | operator<(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5090 | const sub_match<_BiIter>& __y) |
| 5091 | { |
| 5092 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5093 | return __y.compare(string_type(1, __x)) > 0; |
| 5094 | } |
| 5095 | |
| 5096 | template <class _BiIter> |
| 5097 | inline _LIBCPP_INLINE_VISIBILITY |
| 5098 | bool |
| 5099 | operator>(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5100 | const sub_match<_BiIter>& __y) |
| 5101 | { |
| 5102 | return __y < __x; |
| 5103 | } |
| 5104 | |
| 5105 | template <class _BiIter> |
| 5106 | inline _LIBCPP_INLINE_VISIBILITY |
| 5107 | bool |
| 5108 | operator>=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5109 | const sub_match<_BiIter>& __y) |
| 5110 | { |
| 5111 | return !(__x < __y); |
| 5112 | } |
| 5113 | |
| 5114 | template <class _BiIter> |
| 5115 | inline _LIBCPP_INLINE_VISIBILITY |
| 5116 | bool |
| 5117 | operator<=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5118 | const sub_match<_BiIter>& __y) |
| 5119 | { |
| 5120 | return !(__y < __x); |
| 5121 | } |
| 5122 | |
| 5123 | template <class _BiIter> |
| 5124 | inline _LIBCPP_INLINE_VISIBILITY |
| 5125 | bool |
| 5126 | operator==(const sub_match<_BiIter>& __x, |
| 5127 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5128 | { |
| 5129 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5130 | return __x.compare(string_type(1, __y)) == 0; |
| 5131 | } |
| 5132 | |
| 5133 | template <class _BiIter> |
| 5134 | inline _LIBCPP_INLINE_VISIBILITY |
| 5135 | bool |
| 5136 | operator!=(const sub_match<_BiIter>& __x, |
| 5137 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5138 | { |
| 5139 | return !(__x == __y); |
| 5140 | } |
| 5141 | |
| 5142 | template <class _BiIter> |
| 5143 | inline _LIBCPP_INLINE_VISIBILITY |
| 5144 | bool |
| 5145 | operator<(const sub_match<_BiIter>& __x, |
| 5146 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5147 | { |
| 5148 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5149 | return __x.compare(string_type(1, __y)) < 0; |
| 5150 | } |
| 5151 | |
| 5152 | template <class _BiIter> |
| 5153 | inline _LIBCPP_INLINE_VISIBILITY |
| 5154 | bool |
| 5155 | operator>(const sub_match<_BiIter>& __x, |
| 5156 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5157 | { |
| 5158 | return __y < __x; |
| 5159 | } |
| 5160 | |
| 5161 | template <class _BiIter> |
| 5162 | inline _LIBCPP_INLINE_VISIBILITY |
| 5163 | bool |
| 5164 | operator>=(const sub_match<_BiIter>& __x, |
| 5165 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5166 | { |
| 5167 | return !(__x < __y); |
| 5168 | } |
| 5169 | |
| 5170 | template <class _BiIter> |
| 5171 | inline _LIBCPP_INLINE_VISIBILITY |
| 5172 | bool |
| 5173 | operator<=(const sub_match<_BiIter>& __x, |
| 5174 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5175 | { |
| 5176 | return !(__y < __x); |
| 5177 | } |
| 5178 | |
| 5179 | template <class _CharT, class _ST, class _BiIter> |
| 5180 | inline _LIBCPP_INLINE_VISIBILITY |
| 5181 | basic_ostream<_CharT, _ST>& |
| 5182 | operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m) |
| 5183 | { |
| 5184 | return __os << __m.str(); |
| 5185 | } |
| 5186 | |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5187 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 5188 | class _LIBCPP_TYPE_VIS_ONLY match_results |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5189 | { |
| 5190 | public: |
| 5191 | typedef _Allocator allocator_type; |
| 5192 | typedef sub_match<_BidirectionalIterator> value_type; |
| 5193 | private: |
| 5194 | typedef vector<value_type, allocator_type> __container_type; |
| 5195 | |
| 5196 | __container_type __matches_; |
| 5197 | value_type __unmatched_; |
| 5198 | value_type __prefix_; |
| 5199 | value_type __suffix_; |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5200 | bool __ready_; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5201 | public: |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5202 | _BidirectionalIterator __position_start_; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5203 | typedef const value_type& const_reference; |
Marshall Clow | 103af34 | 2014-02-26 01:56:31 +0000 | [diff] [blame] | 5204 | typedef value_type& reference; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5205 | typedef typename __container_type::const_iterator const_iterator; |
| 5206 | typedef const_iterator iterator; |
| 5207 | typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; |
| 5208 | typedef typename allocator_traits<allocator_type>::size_type size_type; |
| 5209 | typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type; |
| 5210 | typedef basic_string<char_type> string_type; |
| 5211 | |
| 5212 | // construct/copy/destroy: |
| 5213 | explicit match_results(const allocator_type& __a = allocator_type()); |
| 5214 | // match_results(const match_results&) = default; |
| 5215 | // match_results& operator=(const match_results&) = default; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5216 | // match_results(match_results&& __m) = default; |
| 5217 | // match_results& operator=(match_results&& __m) = default; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5218 | // ~match_results() = default; |
| 5219 | |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5220 | _LIBCPP_INLINE_VISIBILITY |
| 5221 | bool ready() const {return __ready_;} |
| 5222 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5223 | // size: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5224 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5225 | size_type size() const {return __matches_.size();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5226 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5227 | size_type max_size() const {return __matches_.max_size();} |
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 | bool empty() const {return size() == 0;} |
| 5230 | |
| 5231 | // element access: |
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 | difference_type length(size_type __sub = 0) const |
| 5234 | {return (*this)[__sub].length();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5235 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5236 | difference_type position(size_type __sub = 0) const |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5237 | {return _VSTD::distance(__position_start_, (*this)[__sub].first);} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5238 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5239 | string_type str(size_type __sub = 0) const |
| 5240 | {return (*this)[__sub].str();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5241 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5242 | const_reference operator[](size_type __n) const |
| 5243 | {return __n < __matches_.size() ? __matches_[__n] : __unmatched_;} |
| 5244 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5245 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5246 | const_reference prefix() const {return __prefix_;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5247 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5248 | const_reference suffix() const {return __suffix_;} |
| 5249 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5250 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c6fe8ca | 2011-10-08 14:36:16 +0000 | [diff] [blame] | 5251 | const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5252 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5253 | const_iterator end() const {return __matches_.end();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5254 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c6fe8ca | 2011-10-08 14:36:16 +0000 | [diff] [blame] | 5255 | const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5256 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5257 | const_iterator cend() const {return __matches_.end();} |
| 5258 | |
| 5259 | // format: |
| 5260 | template <class _OutputIter> |
| 5261 | _OutputIter |
| 5262 | format(_OutputIter __out, const char_type* __fmt_first, |
| 5263 | const char_type* __fmt_last, |
| 5264 | regex_constants::match_flag_type __flags = regex_constants::format_default) const; |
| 5265 | template <class _OutputIter, class _ST, class _SA> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5266 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5267 | _OutputIter |
| 5268 | format(_OutputIter __out, const basic_string<char_type, _ST, _SA>& __fmt, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5269 | regex_constants::match_flag_type __flags = regex_constants::format_default) const |
| 5270 | {return format(__out, __fmt.data(), __fmt.data() + __fmt.size(), __flags);} |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5271 | template <class _ST, class _SA> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5272 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5273 | basic_string<char_type, _ST, _SA> |
| 5274 | format(const basic_string<char_type, _ST, _SA>& __fmt, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5275 | regex_constants::match_flag_type __flags = regex_constants::format_default) const |
| 5276 | { |
| 5277 | basic_string<char_type, _ST, _SA> __r; |
| 5278 | format(back_inserter(__r), __fmt.data(), __fmt.data() + __fmt.size(), |
| 5279 | __flags); |
| 5280 | return __r; |
| 5281 | } |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5282 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5283 | string_type |
| 5284 | format(const char_type* __fmt, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5285 | regex_constants::match_flag_type __flags = regex_constants::format_default) const |
| 5286 | { |
| 5287 | string_type __r; |
| 5288 | format(back_inserter(__r), __fmt, |
| 5289 | __fmt + char_traits<char_type>::length(__fmt), __flags); |
| 5290 | return __r; |
| 5291 | } |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5292 | |
| 5293 | // allocator: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5294 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5295 | allocator_type get_allocator() const {return __matches_.get_allocator();} |
| 5296 | |
| 5297 | // swap: |
| 5298 | void swap(match_results& __m); |
| 5299 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5300 | template <class _Bp, class _Ap> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5301 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5302 | void __assign(_BidirectionalIterator __f, _BidirectionalIterator __l, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5303 | const match_results<_Bp, _Ap>& __m, bool __no_update_pos) |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5304 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5305 | _Bp __mf = __m.prefix().first; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5306 | __matches_.resize(__m.size()); |
| 5307 | for (size_type __i = 0; __i < __matches_.size(); ++__i) |
| 5308 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5309 | __matches_[__i].first = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].first)); |
| 5310 | __matches_[__i].second = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].second)); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5311 | __matches_[__i].matched = __m[__i].matched; |
| 5312 | } |
| 5313 | __unmatched_.first = __l; |
| 5314 | __unmatched_.second = __l; |
| 5315 | __unmatched_.matched = false; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5316 | __prefix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().first)); |
| 5317 | __prefix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().second)); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5318 | __prefix_.matched = __m.prefix().matched; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5319 | __suffix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().first)); |
| 5320 | __suffix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().second)); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5321 | __suffix_.matched = __m.suffix().matched; |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5322 | if (!__no_update_pos) |
| 5323 | __position_start_ = __prefix_.first; |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5324 | __ready_ = __m.ready(); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5325 | } |
| 5326 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5327 | private: |
| 5328 | void __init(unsigned __s, |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5329 | _BidirectionalIterator __f, _BidirectionalIterator __l, |
| 5330 | bool __no_update_pos = false); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5331 | |
| 5332 | template <class, class> friend class basic_regex; |
| 5333 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5334 | template <class _Bp, class _Ap, class _Cp, class _Tp> |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5335 | friend |
| 5336 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5337 | 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] | 5338 | regex_constants::match_flag_type); |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 5339 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5340 | template <class _Bp, class _Ap> |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5341 | friend |
| 5342 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5343 | operator==(const match_results<_Bp, _Ap>&, const match_results<_Bp, _Ap>&); |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5344 | |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 5345 | template <class, class> friend class __lookahead; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5346 | }; |
| 5347 | |
| 5348 | template <class _BidirectionalIterator, class _Allocator> |
| 5349 | match_results<_BidirectionalIterator, _Allocator>::match_results( |
| 5350 | const allocator_type& __a) |
| 5351 | : __matches_(__a), |
| 5352 | __unmatched_(), |
| 5353 | __prefix_(), |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5354 | __suffix_(), |
Eric Fiselier | 7cc7106 | 2015-07-22 01:29:41 +0000 | [diff] [blame] | 5355 | __ready_(false), |
| 5356 | __position_start_() |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5357 | { |
| 5358 | } |
| 5359 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5360 | template <class _BidirectionalIterator, class _Allocator> |
| 5361 | void |
| 5362 | match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s, |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5363 | _BidirectionalIterator __f, _BidirectionalIterator __l, |
| 5364 | bool __no_update_pos) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5365 | { |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5366 | __unmatched_.first = __l; |
| 5367 | __unmatched_.second = __l; |
| 5368 | __unmatched_.matched = false; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5369 | __matches_.assign(__s, __unmatched_); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5370 | __prefix_.first = __f; |
| 5371 | __prefix_.second = __f; |
| 5372 | __prefix_.matched = false; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5373 | __suffix_ = __unmatched_; |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5374 | if (!__no_update_pos) |
| 5375 | __position_start_ = __prefix_.first; |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5376 | __ready_ = true; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5377 | } |
| 5378 | |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5379 | template <class _BidirectionalIterator, class _Allocator> |
| 5380 | template <class _OutputIter> |
| 5381 | _OutputIter |
| 5382 | match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __out, |
| 5383 | const char_type* __fmt_first, const char_type* __fmt_last, |
| 5384 | regex_constants::match_flag_type __flags) const |
| 5385 | { |
| 5386 | if (__flags & regex_constants::format_sed) |
| 5387 | { |
| 5388 | for (; __fmt_first != __fmt_last; ++__fmt_first) |
| 5389 | { |
| 5390 | if (*__fmt_first == '&') |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5391 | __out = _VSTD::copy(__matches_[0].first, __matches_[0].second, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5392 | __out); |
| 5393 | else if (*__fmt_first == '\\' && __fmt_first + 1 != __fmt_last) |
| 5394 | { |
| 5395 | ++__fmt_first; |
| 5396 | if ('0' <= *__fmt_first && *__fmt_first <= '9') |
| 5397 | { |
| 5398 | size_t __i = *__fmt_first - '0'; |
Duncan P. N. Exon Smith | e784f57 | 2016-02-03 19:30:20 +0000 | [diff] [blame] | 5399 | __out = _VSTD::copy((*this)[__i].first, |
| 5400 | (*this)[__i].second, __out); |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5401 | } |
| 5402 | else |
| 5403 | { |
| 5404 | *__out = *__fmt_first; |
| 5405 | ++__out; |
| 5406 | } |
| 5407 | } |
| 5408 | else |
| 5409 | { |
| 5410 | *__out = *__fmt_first; |
| 5411 | ++__out; |
| 5412 | } |
| 5413 | } |
| 5414 | } |
| 5415 | else |
| 5416 | { |
| 5417 | for (; __fmt_first != __fmt_last; ++__fmt_first) |
| 5418 | { |
| 5419 | if (*__fmt_first == '$' && __fmt_first + 1 != __fmt_last) |
| 5420 | { |
| 5421 | switch (__fmt_first[1]) |
| 5422 | { |
| 5423 | case '$': |
| 5424 | *__out = *++__fmt_first; |
| 5425 | ++__out; |
| 5426 | break; |
| 5427 | case '&': |
| 5428 | ++__fmt_first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5429 | __out = _VSTD::copy(__matches_[0].first, __matches_[0].second, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5430 | __out); |
| 5431 | break; |
| 5432 | case '`': |
| 5433 | ++__fmt_first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5434 | __out = _VSTD::copy(__prefix_.first, __prefix_.second, __out); |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5435 | break; |
| 5436 | case '\'': |
| 5437 | ++__fmt_first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5438 | __out = _VSTD::copy(__suffix_.first, __suffix_.second, __out); |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5439 | break; |
| 5440 | default: |
| 5441 | if ('0' <= __fmt_first[1] && __fmt_first[1] <= '9') |
| 5442 | { |
| 5443 | ++__fmt_first; |
| 5444 | size_t __i = *__fmt_first - '0'; |
| 5445 | if (__fmt_first + 1 != __fmt_last && |
| 5446 | '0' <= __fmt_first[1] && __fmt_first[1] <= '9') |
| 5447 | { |
| 5448 | ++__fmt_first; |
| 5449 | __i = 10 * __i + *__fmt_first - '0'; |
| 5450 | } |
Duncan P. N. Exon Smith | e784f57 | 2016-02-03 19:30:20 +0000 | [diff] [blame] | 5451 | __out = _VSTD::copy((*this)[__i].first, |
| 5452 | (*this)[__i].second, __out); |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5453 | } |
| 5454 | else |
| 5455 | { |
| 5456 | *__out = *__fmt_first; |
| 5457 | ++__out; |
| 5458 | } |
| 5459 | break; |
| 5460 | } |
| 5461 | } |
| 5462 | else |
| 5463 | { |
| 5464 | *__out = *__fmt_first; |
| 5465 | ++__out; |
| 5466 | } |
| 5467 | } |
| 5468 | } |
| 5469 | return __out; |
| 5470 | } |
| 5471 | |
| 5472 | template <class _BidirectionalIterator, class _Allocator> |
| 5473 | void |
| 5474 | match_results<_BidirectionalIterator, _Allocator>::swap(match_results& __m) |
| 5475 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5476 | using _VSTD::swap; |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5477 | swap(__matches_, __m.__matches_); |
| 5478 | swap(__unmatched_, __m.__unmatched_); |
| 5479 | swap(__prefix_, __m.__prefix_); |
| 5480 | swap(__suffix_, __m.__suffix_); |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5481 | swap(__position_start_, __m.__position_start_); |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5482 | swap(__ready_, __m.__ready_); |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5483 | } |
| 5484 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5485 | typedef match_results<const char*> cmatch; |
| 5486 | typedef match_results<const wchar_t*> wcmatch; |
| 5487 | typedef match_results<string::const_iterator> smatch; |
| 5488 | typedef match_results<wstring::const_iterator> wsmatch; |
| 5489 | |
| 5490 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5491 | bool |
| 5492 | operator==(const match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5493 | const match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5494 | { |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5495 | if (__x.__ready_ != __y.__ready_) |
| 5496 | return false; |
| 5497 | if (!__x.__ready_) |
| 5498 | return true; |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5499 | return __x.__matches_ == __y.__matches_ && |
| 5500 | __x.__prefix_ == __y.__prefix_ && |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5501 | __x.__suffix_ == __y.__suffix_; |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5502 | } |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5503 | |
| 5504 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5505 | inline _LIBCPP_INLINE_VISIBILITY |
| 5506 | bool |
| 5507 | operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5508 | const match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5509 | { |
| 5510 | return !(__x == __y); |
| 5511 | } |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5512 | |
| 5513 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5514 | inline _LIBCPP_INLINE_VISIBILITY |
| 5515 | void |
| 5516 | swap(match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5517 | match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5518 | { |
| 5519 | __x.swap(__y); |
| 5520 | } |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5521 | |
| 5522 | // regex_search |
| 5523 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5524 | template <class _CharT, class _Traits> |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5525 | template <class _Allocator> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5526 | bool |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5527 | basic_regex<_CharT, _Traits>::__match_at_start_ecma( |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5528 | const _CharT* __first, const _CharT* __last, |
| 5529 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5530 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5531 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5532 | vector<__state> __states; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5533 | __node* __st = __start_.get(); |
| 5534 | if (__st) |
| 5535 | { |
Marshall Clow | 5e56c30 | 2015-01-28 22:22:35 +0000 | [diff] [blame] | 5536 | sub_match<const _CharT*> __unmatched; |
| 5537 | __unmatched.first = __last; |
| 5538 | __unmatched.second = __last; |
| 5539 | __unmatched.matched = false; |
| 5540 | |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5541 | __states.push_back(__state()); |
| 5542 | __states.back().__do_ = 0; |
| 5543 | __states.back().__first_ = __first; |
| 5544 | __states.back().__current_ = __first; |
| 5545 | __states.back().__last_ = __last; |
Marshall Clow | 5e56c30 | 2015-01-28 22:22:35 +0000 | [diff] [blame] | 5546 | __states.back().__sub_matches_.resize(mark_count(), __unmatched); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5547 | __states.back().__loop_data_.resize(__loop_count()); |
| 5548 | __states.back().__node_ = __st; |
| 5549 | __states.back().__flags_ = __flags; |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5550 | __states.back().__at_first_ = __at_first; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5551 | do |
| 5552 | { |
| 5553 | __state& __s = __states.back(); |
| 5554 | if (__s.__node_) |
| 5555 | __s.__node_->__exec(__s); |
| 5556 | switch (__s.__do_) |
| 5557 | { |
| 5558 | case __state::__end_state: |
| 5559 | __m.__matches_[0].first = __first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5560 | __m.__matches_[0].second = _VSTD::next(__first, __s.__current_ - __first); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5561 | __m.__matches_[0].matched = true; |
| 5562 | for (unsigned __i = 0; __i < __s.__sub_matches_.size(); ++__i) |
| 5563 | __m.__matches_[__i+1] = __s.__sub_matches_[__i]; |
| 5564 | return true; |
| 5565 | case __state::__accept_and_consume: |
| 5566 | case __state::__repeat: |
| 5567 | case __state::__accept_but_not_consume: |
| 5568 | break; |
| 5569 | case __state::__split: |
| 5570 | { |
| 5571 | __state __snext = __s; |
| 5572 | __s.__node_->__exec_split(true, __s); |
| 5573 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5574 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5575 | } |
| 5576 | break; |
| 5577 | case __state::__reject: |
| 5578 | __states.pop_back(); |
| 5579 | break; |
| 5580 | default: |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 5581 | __throw_regex_error<regex_constants::__re_err_unknown>(); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5582 | break; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 5583 | |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5584 | } |
| 5585 | } while (!__states.empty()); |
| 5586 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5587 | return false; |
| 5588 | } |
| 5589 | |
| 5590 | template <class _CharT, class _Traits> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5591 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5592 | bool |
| 5593 | basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs( |
| 5594 | const _CharT* __first, const _CharT* __last, |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5595 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5596 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5597 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5598 | deque<__state> __states; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5599 | ptrdiff_t __highest_j = 0; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5600 | ptrdiff_t _Np = _VSTD::distance(__first, __last); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5601 | __node* __st = __start_.get(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5602 | if (__st) |
| 5603 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5604 | __states.push_back(__state()); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5605 | __states.back().__do_ = 0; |
| 5606 | __states.back().__first_ = __first; |
| 5607 | __states.back().__current_ = __first; |
| 5608 | __states.back().__last_ = __last; |
| 5609 | __states.back().__loop_data_.resize(__loop_count()); |
| 5610 | __states.back().__node_ = __st; |
| 5611 | __states.back().__flags_ = __flags; |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5612 | __states.back().__at_first_ = __at_first; |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5613 | bool __matched = false; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5614 | do |
| 5615 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5616 | __state& __s = __states.back(); |
| 5617 | if (__s.__node_) |
| 5618 | __s.__node_->__exec(__s); |
| 5619 | switch (__s.__do_) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5620 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5621 | case __state::__end_state: |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5622 | if (!__matched || __highest_j < __s.__current_ - __s.__first_) |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5623 | __highest_j = __s.__current_ - __s.__first_; |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5624 | __matched = true; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5625 | if (__highest_j == _Np) |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5626 | __states.clear(); |
| 5627 | else |
| 5628 | __states.pop_back(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5629 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5630 | case __state::__consume_input: |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5631 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5632 | case __state::__accept_and_consume: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5633 | __states.push_front(_VSTD::move(__s)); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5634 | __states.pop_back(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5635 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5636 | case __state::__repeat: |
| 5637 | case __state::__accept_but_not_consume: |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5638 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5639 | case __state::__split: |
| 5640 | { |
| 5641 | __state __snext = __s; |
| 5642 | __s.__node_->__exec_split(true, __s); |
| 5643 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5644 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5645 | } |
| 5646 | break; |
| 5647 | case __state::__reject: |
| 5648 | __states.pop_back(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5649 | break; |
| 5650 | default: |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 5651 | __throw_regex_error<regex_constants::__re_err_unknown>(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5652 | break; |
| 5653 | } |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5654 | } while (!__states.empty()); |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5655 | if (__matched) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5656 | { |
| 5657 | __m.__matches_[0].first = __first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5658 | __m.__matches_[0].second = _VSTD::next(__first, __highest_j); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5659 | __m.__matches_[0].matched = true; |
| 5660 | return true; |
| 5661 | } |
| 5662 | } |
| 5663 | return false; |
| 5664 | } |
| 5665 | |
| 5666 | template <class _CharT, class _Traits> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5667 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5668 | bool |
| 5669 | basic_regex<_CharT, _Traits>::__match_at_start_posix_subs( |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5670 | const _CharT* __first, const _CharT* __last, |
| 5671 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5672 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5673 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5674 | vector<__state> __states; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5675 | __state __best_state; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5676 | ptrdiff_t __j = 0; |
| 5677 | ptrdiff_t __highest_j = 0; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5678 | ptrdiff_t _Np = _VSTD::distance(__first, __last); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5679 | __node* __st = __start_.get(); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5680 | if (__st) |
| 5681 | { |
Marshall Clow | 5e56c30 | 2015-01-28 22:22:35 +0000 | [diff] [blame] | 5682 | sub_match<const _CharT*> __unmatched; |
| 5683 | __unmatched.first = __last; |
| 5684 | __unmatched.second = __last; |
| 5685 | __unmatched.matched = false; |
| 5686 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5687 | __states.push_back(__state()); |
| 5688 | __states.back().__do_ = 0; |
| 5689 | __states.back().__first_ = __first; |
| 5690 | __states.back().__current_ = __first; |
| 5691 | __states.back().__last_ = __last; |
Marshall Clow | 5e56c30 | 2015-01-28 22:22:35 +0000 | [diff] [blame] | 5692 | __states.back().__sub_matches_.resize(mark_count(), __unmatched); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5693 | __states.back().__loop_data_.resize(__loop_count()); |
| 5694 | __states.back().__node_ = __st; |
| 5695 | __states.back().__flags_ = __flags; |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5696 | __states.back().__at_first_ = __at_first; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5697 | const _CharT* __current = __first; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5698 | bool __matched = false; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5699 | do |
| 5700 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5701 | __state& __s = __states.back(); |
| 5702 | if (__s.__node_) |
| 5703 | __s.__node_->__exec(__s); |
| 5704 | switch (__s.__do_) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5705 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5706 | case __state::__end_state: |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5707 | if (!__matched || __highest_j < __s.__current_ - __s.__first_) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5708 | { |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5709 | __highest_j = __s.__current_ - __s.__first_; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5710 | __best_state = __s; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5711 | } |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5712 | __matched = true; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5713 | if (__highest_j == _Np) |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5714 | __states.clear(); |
| 5715 | else |
| 5716 | __states.pop_back(); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5717 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5718 | case __state::__accept_and_consume: |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 5719 | __j += __s.__current_ - __current; |
| 5720 | __current = __s.__current_; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5721 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5722 | case __state::__repeat: |
| 5723 | case __state::__accept_but_not_consume: |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5724 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5725 | case __state::__split: |
| 5726 | { |
| 5727 | __state __snext = __s; |
| 5728 | __s.__node_->__exec_split(true, __s); |
| 5729 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5730 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5731 | } |
| 5732 | break; |
| 5733 | case __state::__reject: |
| 5734 | __states.pop_back(); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5735 | break; |
| 5736 | default: |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 5737 | __throw_regex_error<regex_constants::__re_err_unknown>(); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5738 | break; |
| 5739 | } |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5740 | } while (!__states.empty()); |
| 5741 | if (__matched) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5742 | { |
| 5743 | __m.__matches_[0].first = __first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5744 | __m.__matches_[0].second = _VSTD::next(__first, __highest_j); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5745 | __m.__matches_[0].matched = true; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5746 | for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i) |
| 5747 | __m.__matches_[__i+1] = __best_state.__sub_matches_[__i]; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5748 | return true; |
| 5749 | } |
| 5750 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5751 | return false; |
| 5752 | } |
| 5753 | |
| 5754 | template <class _CharT, class _Traits> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5755 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5756 | bool |
| 5757 | basic_regex<_CharT, _Traits>::__match_at_start( |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5758 | const _CharT* __first, const _CharT* __last, |
| 5759 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5760 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5761 | { |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5762 | if ((__flags_ & 0x1F0) == ECMAScript) |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5763 | return __match_at_start_ecma(__first, __last, __m, __flags, __at_first); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5764 | if (mark_count() == 0) |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5765 | return __match_at_start_posix_nosubs(__first, __last, __m, __flags, __at_first); |
| 5766 | return __match_at_start_posix_subs(__first, __last, __m, __flags, __at_first); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5767 | } |
| 5768 | |
| 5769 | template <class _CharT, class _Traits> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5770 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5771 | bool |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5772 | basic_regex<_CharT, _Traits>::__search( |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5773 | const _CharT* __first, const _CharT* __last, |
| 5774 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5775 | regex_constants::match_flag_type __flags) const |
| 5776 | { |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5777 | __m.__init(1 + mark_count(), __first, __last, |
| 5778 | __flags & regex_constants::__no_update_pos); |
Howard Hinnant | 7670f7d | 2013-07-09 17:29:09 +0000 | [diff] [blame] | 5779 | if (__match_at_start(__first, __last, __m, __flags, |
| 5780 | !(__flags & regex_constants::__no_update_pos))) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5781 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5782 | __m.__prefix_.second = __m[0].first; |
| 5783 | __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; |
| 5784 | __m.__suffix_.first = __m[0].second; |
| 5785 | __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; |
| 5786 | return true; |
| 5787 | } |
Howard Hinnant | 8daa733 | 2010-07-29 01:15:27 +0000 | [diff] [blame] | 5788 | if (__first != __last && !(__flags & regex_constants::match_continuous)) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5789 | { |
Howard Hinnant | f3dcca0 | 2010-07-29 15:17:28 +0000 | [diff] [blame] | 5790 | __flags |= regex_constants::match_prev_avail; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5791 | for (++__first; __first != __last; ++__first) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5792 | { |
Howard Hinnant | f3dcca0 | 2010-07-29 15:17:28 +0000 | [diff] [blame] | 5793 | __m.__matches_.assign(__m.size(), __m.__unmatched_); |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5794 | if (__match_at_start(__first, __last, __m, __flags, false)) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5795 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5796 | __m.__prefix_.second = __m[0].first; |
| 5797 | __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; |
| 5798 | __m.__suffix_.first = __m[0].second; |
| 5799 | __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; |
| 5800 | return true; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5801 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5802 | __m.__matches_.assign(__m.size(), __m.__unmatched_); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5803 | } |
| 5804 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5805 | __m.__matches_.clear(); |
| 5806 | return false; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5807 | } |
| 5808 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5809 | template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5810 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5811 | bool |
| 5812 | regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 5813 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 5814 | const basic_regex<_CharT, _Traits>& __e, |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5815 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5816 | { |
Howard Hinnant | e840208 | 2013-07-11 15:32:55 +0000 | [diff] [blame] | 5817 | int __offset = (__flags & regex_constants::match_prev_avail) ? 1 : 0; |
| 5818 | basic_string<_CharT> __s(_VSTD::prev(__first, __offset), __last); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5819 | match_results<const _CharT*> __mc; |
Howard Hinnant | e840208 | 2013-07-11 15:32:55 +0000 | [diff] [blame] | 5820 | bool __r = __e.__search(__s.data() + __offset, __s.data() + __s.size(), __mc, __flags); |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5821 | __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5822 | return __r; |
| 5823 | } |
| 5824 | |
Howard Hinnant | a9602d5 | 2013-06-29 23:45:43 +0000 | [diff] [blame] | 5825 | template <class _Iter, class _Allocator, class _CharT, class _Traits> |
| 5826 | inline _LIBCPP_INLINE_VISIBILITY |
| 5827 | bool |
| 5828 | regex_search(__wrap_iter<_Iter> __first, |
| 5829 | __wrap_iter<_Iter> __last, |
| 5830 | match_results<__wrap_iter<_Iter>, _Allocator>& __m, |
| 5831 | const basic_regex<_CharT, _Traits>& __e, |
| 5832 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5833 | { |
| 5834 | match_results<const _CharT*> __mc; |
| 5835 | bool __r = __e.__search(__first.base(), __last.base(), __mc, __flags); |
| 5836 | __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos); |
| 5837 | return __r; |
| 5838 | } |
| 5839 | |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5840 | template <class _Allocator, class _CharT, class _Traits> |
| 5841 | inline _LIBCPP_INLINE_VISIBILITY |
| 5842 | bool |
| 5843 | regex_search(const _CharT* __first, const _CharT* __last, |
| 5844 | match_results<const _CharT*, _Allocator>& __m, |
| 5845 | const basic_regex<_CharT, _Traits>& __e, |
| 5846 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5847 | { |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5848 | return __e.__search(__first, __last, __m, __flags); |
| 5849 | } |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5850 | |
| 5851 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 5852 | inline _LIBCPP_INLINE_VISIBILITY |
| 5853 | bool |
| 5854 | regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 5855 | const basic_regex<_CharT, _Traits>& __e, |
| 5856 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5857 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5858 | basic_string<_CharT> __s(__first, __last); |
| 5859 | match_results<const _CharT*> __mc; |
| 5860 | return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
| 5861 | } |
| 5862 | |
| 5863 | template <class _CharT, class _Traits> |
| 5864 | inline _LIBCPP_INLINE_VISIBILITY |
| 5865 | bool |
| 5866 | regex_search(const _CharT* __first, const _CharT* __last, |
| 5867 | const basic_regex<_CharT, _Traits>& __e, |
| 5868 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5869 | { |
| 5870 | match_results<const _CharT*> __mc; |
| 5871 | return __e.__search(__first, __last, __mc, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5872 | } |
| 5873 | |
| 5874 | template <class _CharT, class _Allocator, class _Traits> |
| 5875 | inline _LIBCPP_INLINE_VISIBILITY |
| 5876 | bool |
| 5877 | regex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, |
| 5878 | const basic_regex<_CharT, _Traits>& __e, |
| 5879 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5880 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5881 | return __e.__search(__str, __str + _Traits::length(__str), __m, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5882 | } |
| 5883 | |
| 5884 | template <class _CharT, class _Traits> |
| 5885 | inline _LIBCPP_INLINE_VISIBILITY |
| 5886 | bool |
| 5887 | regex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, |
| 5888 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5889 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5890 | match_results<const _CharT*> __m; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5891 | return _VSTD::regex_search(__str, __m, __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5892 | } |
| 5893 | |
| 5894 | template <class _ST, class _SA, class _CharT, class _Traits> |
| 5895 | inline _LIBCPP_INLINE_VISIBILITY |
| 5896 | bool |
| 5897 | regex_search(const basic_string<_CharT, _ST, _SA>& __s, |
| 5898 | const basic_regex<_CharT, _Traits>& __e, |
| 5899 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5900 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5901 | match_results<const _CharT*> __mc; |
| 5902 | return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5903 | } |
| 5904 | |
| 5905 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 5906 | inline _LIBCPP_INLINE_VISIBILITY |
| 5907 | bool |
| 5908 | regex_search(const basic_string<_CharT, _ST, _SA>& __s, |
| 5909 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 5910 | const basic_regex<_CharT, _Traits>& __e, |
| 5911 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5912 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5913 | match_results<const _CharT*> __mc; |
| 5914 | bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5915 | __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] | 5916 | return __r; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5917 | } |
| 5918 | |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 5919 | #if _LIBCPP_STD_VER > 11 |
| 5920 | template <class _ST, class _SA, class _Ap, class _Cp, class _Tp> |
| 5921 | bool |
| 5922 | regex_search(const basic_string<_Cp, _ST, _SA>&& __s, |
| 5923 | match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&, |
| 5924 | const basic_regex<_Cp, _Tp>& __e, |
| 5925 | regex_constants::match_flag_type __flags = regex_constants::match_default) = delete; |
| 5926 | #endif |
| 5927 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5928 | // regex_match |
| 5929 | |
| 5930 | template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> |
| 5931 | bool |
| 5932 | regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 5933 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 5934 | const basic_regex<_CharT, _Traits>& __e, |
| 5935 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5936 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5937 | bool __r = _VSTD::regex_search(__first, __last, __m, __e, |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5938 | __flags | regex_constants::match_continuous); |
| 5939 | if (__r) |
| 5940 | { |
| 5941 | __r = !__m.suffix().matched; |
| 5942 | if (!__r) |
| 5943 | __m.__matches_.clear(); |
| 5944 | } |
| 5945 | return __r; |
| 5946 | } |
| 5947 | |
| 5948 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 5949 | inline _LIBCPP_INLINE_VISIBILITY |
| 5950 | bool |
| 5951 | regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 5952 | const basic_regex<_CharT, _Traits>& __e, |
| 5953 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5954 | { |
| 5955 | match_results<_BidirectionalIterator> __m; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5956 | return _VSTD::regex_match(__first, __last, __m, __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5957 | } |
| 5958 | |
| 5959 | template <class _CharT, class _Allocator, class _Traits> |
| 5960 | inline _LIBCPP_INLINE_VISIBILITY |
| 5961 | bool |
| 5962 | regex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, |
| 5963 | const basic_regex<_CharT, _Traits>& __e, |
| 5964 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5965 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5966 | return _VSTD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5967 | } |
| 5968 | |
| 5969 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 5970 | inline _LIBCPP_INLINE_VISIBILITY |
| 5971 | bool |
| 5972 | regex_match(const basic_string<_CharT, _ST, _SA>& __s, |
| 5973 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 5974 | const basic_regex<_CharT, _Traits>& __e, |
| 5975 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5976 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5977 | return _VSTD::regex_match(__s.begin(), __s.end(), __m, __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5978 | } |
| 5979 | |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 5980 | #if _LIBCPP_STD_VER > 11 |
| 5981 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 5982 | inline _LIBCPP_INLINE_VISIBILITY |
| 5983 | bool |
| 5984 | regex_match(const basic_string<_CharT, _ST, _SA>&& __s, |
| 5985 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 5986 | const basic_regex<_CharT, _Traits>& __e, |
| 5987 | regex_constants::match_flag_type __flags = regex_constants::match_default) = delete; |
| 5988 | #endif |
| 5989 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5990 | template <class _CharT, class _Traits> |
| 5991 | inline _LIBCPP_INLINE_VISIBILITY |
| 5992 | bool |
| 5993 | regex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, |
| 5994 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5995 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5996 | return _VSTD::regex_match(__str, __str + _Traits::length(__str), __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5997 | } |
| 5998 | |
| 5999 | template <class _ST, class _SA, class _CharT, class _Traits> |
| 6000 | inline _LIBCPP_INLINE_VISIBILITY |
| 6001 | bool |
| 6002 | regex_match(const basic_string<_CharT, _ST, _SA>& __s, |
| 6003 | const basic_regex<_CharT, _Traits>& __e, |
| 6004 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6005 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6006 | return _VSTD::regex_match(__s.begin(), __s.end(), __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6007 | } |
| 6008 | |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6009 | // regex_iterator |
| 6010 | |
| 6011 | template <class _BidirectionalIterator, |
| 6012 | class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type, |
| 6013 | class _Traits = regex_traits<_CharT> > |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 6014 | class _LIBCPP_TYPE_VIS_ONLY regex_iterator |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6015 | { |
| 6016 | public: |
| 6017 | typedef basic_regex<_CharT, _Traits> regex_type; |
| 6018 | typedef match_results<_BidirectionalIterator> value_type; |
| 6019 | typedef ptrdiff_t difference_type; |
| 6020 | typedef const value_type* pointer; |
| 6021 | typedef const value_type& reference; |
| 6022 | typedef forward_iterator_tag iterator_category; |
| 6023 | |
| 6024 | private: |
| 6025 | _BidirectionalIterator __begin_; |
| 6026 | _BidirectionalIterator __end_; |
| 6027 | const regex_type* __pregex_; |
| 6028 | regex_constants::match_flag_type __flags_; |
| 6029 | value_type __match_; |
| 6030 | |
| 6031 | public: |
| 6032 | regex_iterator(); |
| 6033 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6034 | const regex_type& __re, |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6035 | regex_constants::match_flag_type __m |
| 6036 | = regex_constants::match_default); |
| 6037 | #if _LIBCPP_STD_VER > 11 |
| 6038 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6039 | const regex_type&& __re, |
| 6040 | regex_constants::match_flag_type __m |
| 6041 | = regex_constants::match_default) = delete; |
| 6042 | #endif |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6043 | |
| 6044 | bool operator==(const regex_iterator& __x) const; |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6045 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6046 | bool operator!=(const regex_iterator& __x) const {return !(*this == __x);} |
| 6047 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6048 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6049 | reference operator*() const {return __match_;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6050 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6051 | pointer operator->() const {return &__match_;} |
| 6052 | |
| 6053 | regex_iterator& operator++(); |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6054 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6055 | regex_iterator operator++(int) |
| 6056 | { |
| 6057 | regex_iterator __t(*this); |
| 6058 | ++(*this); |
| 6059 | return __t; |
| 6060 | } |
| 6061 | }; |
| 6062 | |
| 6063 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6064 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_iterator() |
| 6065 | : __begin_(), __end_(), __pregex_(nullptr), __flags_(), __match_() |
| 6066 | { |
| 6067 | } |
| 6068 | |
| 6069 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6070 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6071 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6072 | const regex_type& __re, regex_constants::match_flag_type __m) |
| 6073 | : __begin_(__a), |
| 6074 | __end_(__b), |
| 6075 | __pregex_(&__re), |
| 6076 | __flags_(__m) |
| 6077 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6078 | _VSTD::regex_search(__begin_, __end_, __match_, *__pregex_, __flags_); |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6079 | } |
| 6080 | |
| 6081 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6082 | bool |
| 6083 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6084 | operator==(const regex_iterator& __x) const |
| 6085 | { |
| 6086 | if (__match_.empty() && __x.__match_.empty()) |
| 6087 | return true; |
| 6088 | if (__match_.empty() || __x.__match_.empty()) |
| 6089 | return false; |
| 6090 | return __begin_ == __x.__begin_ && |
| 6091 | __end_ == __x.__end_ && |
| 6092 | __pregex_ == __x.__pregex_ && |
| 6093 | __flags_ == __x.__flags_ && |
| 6094 | __match_[0] == __x.__match_[0]; |
| 6095 | } |
| 6096 | |
| 6097 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6098 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6099 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() |
| 6100 | { |
| 6101 | __flags_ |= regex_constants::__no_update_pos; |
| 6102 | _BidirectionalIterator __start = __match_[0].second; |
Howard Hinnant | a9602d5 | 2013-06-29 23:45:43 +0000 | [diff] [blame] | 6103 | if (__match_.empty()) |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6104 | { |
| 6105 | if (__start == __end_) |
| 6106 | { |
| 6107 | __match_ = value_type(); |
| 6108 | return *this; |
| 6109 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6110 | else if (_VSTD::regex_search(__start, __end_, __match_, *__pregex_, |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6111 | __flags_ | regex_constants::match_not_null | |
| 6112 | regex_constants::match_continuous)) |
| 6113 | return *this; |
| 6114 | else |
| 6115 | ++__start; |
| 6116 | } |
| 6117 | __flags_ |= regex_constants::match_prev_avail; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6118 | if (!_VSTD::regex_search(__start, __end_, __match_, *__pregex_, __flags_)) |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6119 | __match_ = value_type(); |
| 6120 | return *this; |
| 6121 | } |
| 6122 | |
| 6123 | typedef regex_iterator<const char*> cregex_iterator; |
| 6124 | typedef regex_iterator<const wchar_t*> wcregex_iterator; |
| 6125 | typedef regex_iterator<string::const_iterator> sregex_iterator; |
| 6126 | typedef regex_iterator<wstring::const_iterator> wsregex_iterator; |
| 6127 | |
| 6128 | // regex_token_iterator |
| 6129 | |
| 6130 | template <class _BidirectionalIterator, |
| 6131 | class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type, |
| 6132 | class _Traits = regex_traits<_CharT> > |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 6133 | class _LIBCPP_TYPE_VIS_ONLY regex_token_iterator |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6134 | { |
| 6135 | public: |
| 6136 | typedef basic_regex<_CharT, _Traits> regex_type; |
| 6137 | typedef sub_match<_BidirectionalIterator> value_type; |
| 6138 | typedef ptrdiff_t difference_type; |
| 6139 | typedef const value_type* pointer; |
| 6140 | typedef const value_type& reference; |
| 6141 | typedef forward_iterator_tag iterator_category; |
| 6142 | |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6143 | private: |
| 6144 | typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position; |
| 6145 | |
| 6146 | _Position __position_; |
| 6147 | const value_type* __result_; |
| 6148 | value_type __suffix_; |
| 6149 | ptrdiff_t _N_; |
| 6150 | vector<int> __subs_; |
| 6151 | |
| 6152 | public: |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6153 | regex_token_iterator(); |
| 6154 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6155 | const regex_type& __re, int __submatch = 0, |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6156 | regex_constants::match_flag_type __m = |
| 6157 | regex_constants::match_default); |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6158 | #if _LIBCPP_STD_VER > 11 |
| 6159 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6160 | const regex_type&& __re, int __submatch = 0, |
| 6161 | regex_constants::match_flag_type __m = |
| 6162 | regex_constants::match_default) = delete; |
| 6163 | #endif |
| 6164 | |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6165 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6166 | const regex_type& __re, const vector<int>& __submatches, |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6167 | regex_constants::match_flag_type __m = |
| 6168 | regex_constants::match_default); |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6169 | #if _LIBCPP_STD_VER > 11 |
| 6170 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6171 | const regex_type&& __re, const vector<int>& __submatches, |
| 6172 | regex_constants::match_flag_type __m = |
| 6173 | regex_constants::match_default) = delete; |
| 6174 | #endif |
| 6175 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6176 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6177 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6178 | const regex_type& __re, |
| 6179 | initializer_list<int> __submatches, |
| 6180 | regex_constants::match_flag_type __m = |
| 6181 | regex_constants::match_default); |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6182 | |
| 6183 | #if _LIBCPP_STD_VER > 11 |
| 6184 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6185 | const regex_type&& __re, |
| 6186 | initializer_list<int> __submatches, |
| 6187 | regex_constants::match_flag_type __m = |
| 6188 | regex_constants::match_default) = delete; |
| 6189 | #endif |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6190 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6191 | template <size_t _Np> |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6192 | regex_token_iterator(_BidirectionalIterator __a, |
| 6193 | _BidirectionalIterator __b, |
| 6194 | const regex_type& __re, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6195 | const int (&__submatches)[_Np], |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6196 | regex_constants::match_flag_type __m = |
| 6197 | regex_constants::match_default); |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6198 | #if _LIBCPP_STD_VER > 11 |
| 6199 | template <std::size_t _Np> |
| 6200 | regex_token_iterator(_BidirectionalIterator __a, |
| 6201 | _BidirectionalIterator __b, |
| 6202 | const regex_type&& __re, |
| 6203 | const int (&__submatches)[_Np], |
| 6204 | regex_constants::match_flag_type __m = |
| 6205 | regex_constants::match_default) = delete; |
| 6206 | #endif |
| 6207 | |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6208 | regex_token_iterator(const regex_token_iterator&); |
| 6209 | regex_token_iterator& operator=(const regex_token_iterator&); |
| 6210 | |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6211 | bool operator==(const regex_token_iterator& __x) const; |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6212 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6213 | bool operator!=(const regex_token_iterator& __x) const {return !(*this == __x);} |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6214 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6215 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6216 | const value_type& operator*() const {return *__result_;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6217 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6218 | const value_type* operator->() const {return __result_;} |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6219 | |
| 6220 | regex_token_iterator& operator++(); |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6221 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6222 | regex_token_iterator operator++(int) |
| 6223 | { |
| 6224 | regex_token_iterator __t(*this); |
| 6225 | ++(*this); |
| 6226 | return __t; |
| 6227 | } |
| 6228 | |
| 6229 | private: |
| 6230 | void __init(_BidirectionalIterator __a, _BidirectionalIterator __b); |
Marshall Clow | 0efd9dc | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6231 | void __establish_result () { |
| 6232 | if (__subs_[_N_] == -1) |
| 6233 | __result_ = &__position_->prefix(); |
| 6234 | else |
| 6235 | __result_ = &(*__position_)[__subs_[_N_]]; |
| 6236 | } |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6237 | }; |
| 6238 | |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6239 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6240 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6241 | regex_token_iterator() |
| 6242 | : __result_(nullptr), |
| 6243 | __suffix_(), |
| 6244 | _N_(0) |
| 6245 | { |
| 6246 | } |
| 6247 | |
| 6248 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6249 | void |
| 6250 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6251 | __init(_BidirectionalIterator __a, _BidirectionalIterator __b) |
| 6252 | { |
| 6253 | if (__position_ != _Position()) |
Marshall Clow | 0efd9dc | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6254 | __establish_result (); |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6255 | else if (__subs_[_N_] == -1) |
| 6256 | { |
| 6257 | __suffix_.matched = true; |
| 6258 | __suffix_.first = __a; |
| 6259 | __suffix_.second = __b; |
| 6260 | __result_ = &__suffix_; |
| 6261 | } |
| 6262 | else |
| 6263 | __result_ = nullptr; |
| 6264 | } |
| 6265 | |
| 6266 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6267 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6268 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6269 | const regex_type& __re, int __submatch, |
| 6270 | regex_constants::match_flag_type __m) |
| 6271 | : __position_(__a, __b, __re, __m), |
| 6272 | _N_(0), |
| 6273 | __subs_(1, __submatch) |
| 6274 | { |
| 6275 | __init(__a, __b); |
| 6276 | } |
| 6277 | |
| 6278 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6279 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6280 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6281 | const regex_type& __re, const vector<int>& __submatches, |
| 6282 | regex_constants::match_flag_type __m) |
| 6283 | : __position_(__a, __b, __re, __m), |
| 6284 | _N_(0), |
| 6285 | __subs_(__submatches) |
| 6286 | { |
| 6287 | __init(__a, __b); |
| 6288 | } |
| 6289 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6290 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 6291 | |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6292 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6293 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6294 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6295 | const regex_type& __re, |
| 6296 | initializer_list<int> __submatches, |
| 6297 | regex_constants::match_flag_type __m) |
| 6298 | : __position_(__a, __b, __re, __m), |
| 6299 | _N_(0), |
| 6300 | __subs_(__submatches) |
| 6301 | { |
| 6302 | __init(__a, __b); |
| 6303 | } |
| 6304 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6305 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 6306 | |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6307 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6308 | template <size_t _Np> |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6309 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6310 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6311 | const regex_type& __re, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6312 | const int (&__submatches)[_Np], |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6313 | regex_constants::match_flag_type __m) |
| 6314 | : __position_(__a, __b, __re, __m), |
| 6315 | _N_(0), |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6316 | __subs_(__submatches, __submatches + _Np) |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6317 | { |
| 6318 | __init(__a, __b); |
| 6319 | } |
| 6320 | |
| 6321 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6322 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6323 | regex_token_iterator(const regex_token_iterator& __x) |
| 6324 | : __position_(__x.__position_), |
| 6325 | __result_(__x.__result_), |
| 6326 | __suffix_(__x.__suffix_), |
| 6327 | _N_(__x._N_), |
| 6328 | __subs_(__x.__subs_) |
| 6329 | { |
| 6330 | if (__x.__result_ == &__x.__suffix_) |
Marshall Clow | 72fe0ae | 2014-01-13 17:47:08 +0000 | [diff] [blame] | 6331 | __result_ = &__suffix_; |
Marshall Clow | 0efd9dc | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6332 | else if ( __result_ != nullptr ) |
| 6333 | __establish_result (); |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6334 | } |
| 6335 | |
| 6336 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6337 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6338 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6339 | operator=(const regex_token_iterator& __x) |
| 6340 | { |
| 6341 | if (this != &__x) |
| 6342 | { |
| 6343 | __position_ = __x.__position_; |
| 6344 | if (__x.__result_ == &__x.__suffix_) |
Marshall Clow | 0efd9dc | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6345 | __result_ = &__suffix_; |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6346 | else |
| 6347 | __result_ = __x.__result_; |
| 6348 | __suffix_ = __x.__suffix_; |
| 6349 | _N_ = __x._N_; |
| 6350 | __subs_ = __x.__subs_; |
Marshall Clow | 0efd9dc | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6351 | |
| 6352 | if ( __result_ != nullptr && __result_ != &__suffix_ ) |
| 6353 | __establish_result(); |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6354 | } |
| 6355 | return *this; |
| 6356 | } |
| 6357 | |
| 6358 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6359 | bool |
| 6360 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6361 | operator==(const regex_token_iterator& __x) const |
| 6362 | { |
| 6363 | if (__result_ == nullptr && __x.__result_ == nullptr) |
| 6364 | return true; |
| 6365 | if (__result_ == &__suffix_ && __x.__result_ == &__x.__suffix_ && |
| 6366 | __suffix_ == __x.__suffix_) |
| 6367 | return true; |
| 6368 | if (__result_ == nullptr || __x.__result_ == nullptr) |
| 6369 | return false; |
| 6370 | if (__result_ == &__suffix_ || __x.__result_ == &__x.__suffix_) |
| 6371 | return false; |
| 6372 | return __position_ == __x.__position_ && _N_ == __x._N_ && |
| 6373 | __subs_ == __x.__subs_; |
| 6374 | } |
| 6375 | |
| 6376 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6377 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6378 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() |
| 6379 | { |
| 6380 | _Position __prev = __position_; |
| 6381 | if (__result_ == &__suffix_) |
| 6382 | __result_ = nullptr; |
| 6383 | else if (_N_ + 1 < __subs_.size()) |
| 6384 | { |
| 6385 | ++_N_; |
Marshall Clow | 0efd9dc | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6386 | __establish_result(); |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6387 | } |
| 6388 | else |
| 6389 | { |
| 6390 | _N_ = 0; |
| 6391 | ++__position_; |
| 6392 | if (__position_ != _Position()) |
Marshall Clow | 0efd9dc | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6393 | __establish_result(); |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6394 | else |
| 6395 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6396 | if (_VSTD::find(__subs_.begin(), __subs_.end(), -1) != __subs_.end() |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6397 | && __prev->suffix().length() != 0) |
| 6398 | { |
| 6399 | __suffix_.matched = true; |
| 6400 | __suffix_.first = __prev->suffix().first; |
| 6401 | __suffix_.second = __prev->suffix().second; |
| 6402 | __result_ = &__suffix_; |
| 6403 | } |
| 6404 | else |
| 6405 | __result_ = nullptr; |
| 6406 | } |
| 6407 | } |
| 6408 | return *this; |
| 6409 | } |
| 6410 | |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6411 | typedef regex_token_iterator<const char*> cregex_token_iterator; |
| 6412 | typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator; |
| 6413 | typedef regex_token_iterator<string::const_iterator> sregex_token_iterator; |
| 6414 | typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator; |
| 6415 | |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6416 | // regex_replace |
| 6417 | |
| 6418 | template <class _OutputIterator, class _BidirectionalIterator, |
| 6419 | class _Traits, class _CharT> |
| 6420 | _OutputIterator |
| 6421 | regex_replace(_OutputIterator __out, |
| 6422 | _BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6423 | const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt, |
| 6424 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6425 | { |
| 6426 | typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Iter; |
| 6427 | _Iter __i(__first, __last, __e, __flags); |
| 6428 | _Iter __eof; |
| 6429 | if (__i == __eof) |
| 6430 | { |
| 6431 | if (!(__flags & regex_constants::format_no_copy)) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6432 | __out = _VSTD::copy(__first, __last, __out); |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6433 | } |
| 6434 | else |
| 6435 | { |
| 6436 | sub_match<_BidirectionalIterator> __lm; |
| 6437 | for (size_t __len = char_traits<_CharT>::length(__fmt); __i != __eof; ++__i) |
| 6438 | { |
| 6439 | if (!(__flags & regex_constants::format_no_copy)) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6440 | __out = _VSTD::copy(__i->prefix().first, __i->prefix().second, __out); |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6441 | __out = __i->format(__out, __fmt, __fmt + __len, __flags); |
| 6442 | __lm = __i->suffix(); |
| 6443 | if (__flags & regex_constants::format_first_only) |
| 6444 | break; |
| 6445 | } |
| 6446 | if (!(__flags & regex_constants::format_no_copy)) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6447 | __out = _VSTD::copy(__lm.first, __lm.second, __out); |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6448 | } |
| 6449 | return __out; |
| 6450 | } |
| 6451 | |
| 6452 | template <class _OutputIterator, class _BidirectionalIterator, |
| 6453 | class _Traits, class _CharT, class _ST, class _SA> |
| 6454 | inline _LIBCPP_INLINE_VISIBILITY |
| 6455 | _OutputIterator |
| 6456 | regex_replace(_OutputIterator __out, |
| 6457 | _BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6458 | const basic_regex<_CharT, _Traits>& __e, |
| 6459 | const basic_string<_CharT, _ST, _SA>& __fmt, |
| 6460 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6461 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6462 | return _VSTD::regex_replace(__out, __first, __last, __e, __fmt.c_str(), __flags); |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6463 | } |
| 6464 | |
| 6465 | template <class _Traits, class _CharT, class _ST, class _SA, class _FST, |
| 6466 | class _FSA> |
| 6467 | inline _LIBCPP_INLINE_VISIBILITY |
| 6468 | basic_string<_CharT, _ST, _SA> |
| 6469 | regex_replace(const basic_string<_CharT, _ST, _SA>& __s, |
| 6470 | const basic_regex<_CharT, _Traits>& __e, |
| 6471 | const basic_string<_CharT, _FST, _FSA>& __fmt, |
| 6472 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6473 | { |
| 6474 | basic_string<_CharT, _ST, _SA> __r; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6475 | _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e, |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6476 | __fmt.c_str(), __flags); |
| 6477 | return __r; |
| 6478 | } |
| 6479 | |
| 6480 | template <class _Traits, class _CharT, class _ST, class _SA> |
| 6481 | inline _LIBCPP_INLINE_VISIBILITY |
| 6482 | basic_string<_CharT, _ST, _SA> |
| 6483 | regex_replace(const basic_string<_CharT, _ST, _SA>& __s, |
| 6484 | const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt, |
| 6485 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6486 | { |
| 6487 | basic_string<_CharT, _ST, _SA> __r; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6488 | _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e, |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6489 | __fmt, __flags); |
| 6490 | return __r; |
| 6491 | } |
| 6492 | |
| 6493 | template <class _Traits, class _CharT, class _ST, class _SA> |
| 6494 | inline _LIBCPP_INLINE_VISIBILITY |
| 6495 | basic_string<_CharT> |
| 6496 | regex_replace(const _CharT* __s, |
| 6497 | const basic_regex<_CharT, _Traits>& __e, |
| 6498 | const basic_string<_CharT, _ST, _SA>& __fmt, |
| 6499 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6500 | { |
| 6501 | basic_string<_CharT> __r; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6502 | _VSTD::regex_replace(back_inserter(__r), __s, |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6503 | __s + char_traits<_CharT>::length(__s), __e, |
| 6504 | __fmt.c_str(), __flags); |
| 6505 | return __r; |
| 6506 | } |
| 6507 | |
| 6508 | template <class _Traits, class _CharT> |
| 6509 | inline _LIBCPP_INLINE_VISIBILITY |
| 6510 | basic_string<_CharT> |
| 6511 | regex_replace(const _CharT* __s, |
| 6512 | const basic_regex<_CharT, _Traits>& __e, |
| 6513 | const _CharT* __fmt, |
| 6514 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6515 | { |
| 6516 | basic_string<_CharT> __r; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6517 | _VSTD::regex_replace(back_inserter(__r), __s, |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6518 | __s + char_traits<_CharT>::length(__s), __e, |
| 6519 | __fmt, __flags); |
| 6520 | return __r; |
| 6521 | } |
| 6522 | |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 6523 | _LIBCPP_END_NAMESPACE_STD |
| 6524 | |
| 6525 | #endif // _LIBCPP_REGEX |