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