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