| 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 | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 724 |  | 
|  | 725 | #pragma GCC system_header | 
|  | 726 |  | 
|  | 727 | _LIBCPP_BEGIN_NAMESPACE_STD | 
|  | 728 |  | 
|  | 729 | namespace regex_constants | 
|  | 730 | { | 
|  | 731 |  | 
|  | 732 | // syntax_option_type | 
|  | 733 |  | 
|  | 734 | enum syntax_option_type | 
|  | 735 | { | 
|  | 736 | icase      = 1 << 0, | 
|  | 737 | nosubs     = 1 << 1, | 
|  | 738 | optimize   = 1 << 2, | 
|  | 739 | collate    = 1 << 3, | 
|  | 740 | ECMAScript = 1 << 4, | 
|  | 741 | basic      = 1 << 5, | 
|  | 742 | extended   = 1 << 6, | 
|  | 743 | awk        = 1 << 7, | 
|  | 744 | grep       = 1 << 8, | 
|  | 745 | egrep      = 1 << 9 | 
|  | 746 | }; | 
|  | 747 |  | 
|  | 748 | inline | 
|  | 749 | /*constexpr*/ | 
|  | 750 | syntax_option_type | 
|  | 751 | operator~(syntax_option_type __x) | 
|  | 752 | { | 
|  | 753 | return syntax_option_type(~int(__x)); | 
|  | 754 | } | 
|  | 755 |  | 
|  | 756 | inline | 
|  | 757 | /*constexpr*/ | 
|  | 758 | syntax_option_type | 
|  | 759 | operator&(syntax_option_type __x, syntax_option_type __y) | 
|  | 760 | { | 
|  | 761 | return syntax_option_type(int(__x) & int(__y)); | 
|  | 762 | } | 
|  | 763 |  | 
|  | 764 | inline | 
|  | 765 | /*constexpr*/ | 
|  | 766 | syntax_option_type | 
|  | 767 | operator|(syntax_option_type __x, syntax_option_type __y) | 
|  | 768 | { | 
|  | 769 | return syntax_option_type(int(__x) | int(__y)); | 
|  | 770 | } | 
|  | 771 |  | 
|  | 772 | inline | 
|  | 773 | /*constexpr*/ | 
|  | 774 | syntax_option_type | 
|  | 775 | operator^(syntax_option_type __x, syntax_option_type __y) | 
|  | 776 | { | 
|  | 777 | return syntax_option_type(int(__x) ^ int(__y)); | 
|  | 778 | } | 
|  | 779 |  | 
|  | 780 | inline | 
|  | 781 | /*constexpr*/ | 
|  | 782 | syntax_option_type& | 
|  | 783 | operator&=(syntax_option_type& __x, syntax_option_type __y) | 
|  | 784 | { | 
|  | 785 | __x = __x & __y; | 
|  | 786 | return __x; | 
|  | 787 | } | 
|  | 788 |  | 
|  | 789 | inline | 
|  | 790 | /*constexpr*/ | 
|  | 791 | syntax_option_type& | 
|  | 792 | operator|=(syntax_option_type& __x, syntax_option_type __y) | 
|  | 793 | { | 
|  | 794 | __x = __x | __y; | 
|  | 795 | return __x; | 
|  | 796 | } | 
|  | 797 |  | 
|  | 798 | inline | 
|  | 799 | /*constexpr*/ | 
|  | 800 | syntax_option_type& | 
|  | 801 | operator^=(syntax_option_type& __x, syntax_option_type __y) | 
|  | 802 | { | 
|  | 803 | __x = __x ^ __y; | 
|  | 804 | return __x; | 
|  | 805 | } | 
|  | 806 |  | 
|  | 807 | // match_flag_type | 
|  | 808 |  | 
|  | 809 | enum match_flag_type | 
|  | 810 | { | 
|  | 811 | match_default     = 0, | 
|  | 812 | match_not_bol     = 1 << 0, | 
|  | 813 | match_not_eol     = 1 << 1, | 
|  | 814 | match_not_bow     = 1 << 2, | 
|  | 815 | match_not_eow     = 1 << 3, | 
|  | 816 | match_any         = 1 << 4, | 
|  | 817 | match_not_null    = 1 << 5, | 
|  | 818 | match_continuous  = 1 << 6, | 
|  | 819 | match_prev_avail  = 1 << 7, | 
|  | 820 | format_default    = 0, | 
|  | 821 | format_sed        = 1 << 8, | 
|  | 822 | format_no_copy    = 1 << 9, | 
|  | 823 | format_first_only = 1 << 10 | 
|  | 824 | }; | 
|  | 825 |  | 
|  | 826 | inline | 
|  | 827 | /*constexpr*/ | 
|  | 828 | match_flag_type | 
|  | 829 | operator~(match_flag_type __x) | 
|  | 830 | { | 
|  | 831 | return match_flag_type(~int(__x)); | 
|  | 832 | } | 
|  | 833 |  | 
|  | 834 | inline | 
|  | 835 | /*constexpr*/ | 
|  | 836 | match_flag_type | 
|  | 837 | operator&(match_flag_type __x, match_flag_type __y) | 
|  | 838 | { | 
|  | 839 | return match_flag_type(int(__x) & int(__y)); | 
|  | 840 | } | 
|  | 841 |  | 
|  | 842 | inline | 
|  | 843 | /*constexpr*/ | 
|  | 844 | match_flag_type | 
|  | 845 | operator|(match_flag_type __x, match_flag_type __y) | 
|  | 846 | { | 
|  | 847 | return match_flag_type(int(__x) | int(__y)); | 
|  | 848 | } | 
|  | 849 |  | 
|  | 850 | inline | 
|  | 851 | /*constexpr*/ | 
|  | 852 | match_flag_type | 
|  | 853 | operator^(match_flag_type __x, match_flag_type __y) | 
|  | 854 | { | 
|  | 855 | return match_flag_type(int(__x) ^ int(__y)); | 
|  | 856 | } | 
|  | 857 |  | 
|  | 858 | inline | 
|  | 859 | /*constexpr*/ | 
|  | 860 | match_flag_type& | 
|  | 861 | operator&=(match_flag_type& __x, match_flag_type __y) | 
|  | 862 | { | 
|  | 863 | __x = __x & __y; | 
|  | 864 | return __x; | 
|  | 865 | } | 
|  | 866 |  | 
|  | 867 | inline | 
|  | 868 | /*constexpr*/ | 
|  | 869 | match_flag_type& | 
|  | 870 | operator|=(match_flag_type& __x, match_flag_type __y) | 
|  | 871 | { | 
|  | 872 | __x = __x | __y; | 
|  | 873 | return __x; | 
|  | 874 | } | 
|  | 875 |  | 
|  | 876 | inline | 
|  | 877 | /*constexpr*/ | 
|  | 878 | match_flag_type& | 
|  | 879 | operator^=(match_flag_type& __x, match_flag_type __y) | 
|  | 880 | { | 
|  | 881 | __x = __x ^ __y; | 
|  | 882 | return __x; | 
|  | 883 | } | 
|  | 884 |  | 
|  | 885 | enum error_type | 
|  | 886 | { | 
|  | 887 | error_collate = 1, | 
|  | 888 | error_ctype, | 
|  | 889 | error_escape, | 
|  | 890 | error_backref, | 
|  | 891 | error_brack, | 
|  | 892 | error_paren, | 
|  | 893 | error_brace, | 
|  | 894 | error_badbrace, | 
|  | 895 | error_range, | 
|  | 896 | error_space, | 
|  | 897 | error_badrepeat, | 
|  | 898 | error_complexity, | 
| Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame^] | 899 | error_stack, | 
|  | 900 | error_temp | 
| Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 901 | }; | 
|  | 902 |  | 
|  | 903 | }  // regex_constants | 
|  | 904 |  | 
|  | 905 | class _LIBCPP_EXCEPTION_ABI regex_error | 
|  | 906 | : public runtime_error | 
|  | 907 | { | 
|  | 908 | regex_constants::error_type __code_; | 
|  | 909 | public: | 
|  | 910 | explicit regex_error(regex_constants::error_type __ecode); | 
|  | 911 | virtual ~regex_error() throw(); | 
|  | 912 | regex_constants::error_type code() const {return __code_;} | 
|  | 913 | }; | 
|  | 914 |  | 
|  | 915 | template <class _CharT> | 
|  | 916 | struct regex_traits | 
|  | 917 | { | 
|  | 918 | public: | 
|  | 919 | typedef _CharT                  char_type; | 
|  | 920 | typedef basic_string<char_type> string_type; | 
|  | 921 | typedef locale                  locale_type; | 
| Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 922 | typedef ctype_base::mask        char_class_type; | 
| Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 923 |  | 
| Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 924 | static const char_class_type __regex_word = 0x80; | 
| Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 925 | private: | 
|  | 926 | locale __loc_; | 
|  | 927 | const ctype<char_type>* __ct_; | 
|  | 928 | const collate<char_type>* __col_; | 
|  | 929 |  | 
|  | 930 | public: | 
|  | 931 | regex_traits(); | 
|  | 932 |  | 
|  | 933 | static size_t length(const char_type* __p) | 
|  | 934 | {return char_traits<char_type>::length(__p);} | 
|  | 935 | char_type translate(char_type __c) const {return __c;} | 
|  | 936 | char_type translate_nocase(char_type __c) const; | 
|  | 937 | template <class _ForwardIterator> | 
|  | 938 | string_type | 
|  | 939 | transform(_ForwardIterator __f, _ForwardIterator __l) const; | 
|  | 940 | template <class _ForwardIterator> | 
|  | 941 | string_type | 
|  | 942 | transform_primary( _ForwardIterator __f, _ForwardIterator __l) const | 
|  | 943 | {return __transform_primary(__f, __l, char_type());} | 
|  | 944 | template <class _ForwardIterator> | 
|  | 945 | string_type | 
|  | 946 | lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const | 
|  | 947 | {return __lookup_collatename(__f, __l, char_type());} | 
|  | 948 | template <class _ForwardIterator> | 
|  | 949 | char_class_type | 
|  | 950 | lookup_classname(_ForwardIterator __f, _ForwardIterator __l, | 
| Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 951 | bool __icase = false) const | 
|  | 952 | {return __lookup_classname(__f, __l, __icase, char_type());} | 
|  | 953 | bool isctype(char_type __c, char_class_type __m) const; | 
|  | 954 | int value(char_type __ch, int __radix) const | 
|  | 955 | {return __value(__ch, __radix);} | 
| Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 956 | locale_type imbue(locale_type __l); | 
|  | 957 | locale_type getloc()const {return __loc_;} | 
|  | 958 |  | 
|  | 959 | private: | 
|  | 960 | void __init(); | 
|  | 961 |  | 
|  | 962 | template <class _ForwardIterator> | 
|  | 963 | string_type | 
|  | 964 | __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const; | 
|  | 965 | template <class _ForwardIterator> | 
|  | 966 | string_type | 
|  | 967 | __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; | 
|  | 968 |  | 
|  | 969 | template <class _ForwardIterator> | 
|  | 970 | string_type | 
|  | 971 | __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const; | 
|  | 972 | template <class _ForwardIterator> | 
|  | 973 | string_type | 
|  | 974 | __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; | 
| Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 975 |  | 
|  | 976 | template <class _ForwardIterator> | 
|  | 977 | char_class_type | 
|  | 978 | __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, | 
|  | 979 | bool __icase, char) const; | 
|  | 980 | template <class _ForwardIterator> | 
|  | 981 | char_class_type | 
|  | 982 | __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, | 
|  | 983 | bool __icase, wchar_t) const; | 
|  | 984 |  | 
|  | 985 | static int __value(unsigned char __ch, int __radix); | 
|  | 986 | int __value(char __ch, int __radix) const | 
|  | 987 | {return __value(static_cast<unsigned char>(__ch), __radix);} | 
|  | 988 | int __value(wchar_t __ch, int __radix) const; | 
| Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 989 | }; | 
|  | 990 |  | 
|  | 991 | template <class _CharT> | 
|  | 992 | regex_traits<_CharT>::regex_traits() | 
|  | 993 | { | 
|  | 994 | __init(); | 
|  | 995 | } | 
|  | 996 |  | 
|  | 997 | template <class _CharT> | 
|  | 998 | typename regex_traits<_CharT>::char_type | 
|  | 999 | regex_traits<_CharT>::translate_nocase(char_type __c) const | 
|  | 1000 | { | 
|  | 1001 | return __ct_->tolower(__c); | 
|  | 1002 | } | 
|  | 1003 |  | 
|  | 1004 | template <class _CharT> | 
|  | 1005 | template <class _ForwardIterator> | 
|  | 1006 | typename regex_traits<_CharT>::string_type | 
|  | 1007 | regex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const | 
|  | 1008 | { | 
|  | 1009 | string_type __s(__f, __l); | 
|  | 1010 | return __col_->transform(__s.data(), __s.data() + __s.size()); | 
|  | 1011 | } | 
|  | 1012 |  | 
|  | 1013 | template <class _CharT> | 
|  | 1014 | void | 
|  | 1015 | regex_traits<_CharT>::__init() | 
|  | 1016 | { | 
|  | 1017 | __ct_ = &use_facet<ctype<char_type> >(__loc_); | 
|  | 1018 | __col_ = &use_facet<collate<char_type> >(__loc_); | 
|  | 1019 | } | 
|  | 1020 |  | 
|  | 1021 | template <class _CharT> | 
|  | 1022 | typename regex_traits<_CharT>::locale_type | 
|  | 1023 | regex_traits<_CharT>::imbue(locale_type __l) | 
|  | 1024 | { | 
|  | 1025 | locale __r = __loc_; | 
|  | 1026 | __loc_ = __l; | 
|  | 1027 | __init(); | 
|  | 1028 | return __r; | 
|  | 1029 | } | 
|  | 1030 |  | 
|  | 1031 | // transform_primary is very FreeBSD-specific | 
|  | 1032 |  | 
|  | 1033 | template <class _CharT> | 
|  | 1034 | template <class _ForwardIterator> | 
|  | 1035 | typename regex_traits<_CharT>::string_type | 
|  | 1036 | regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, | 
|  | 1037 | _ForwardIterator __l, char) const | 
|  | 1038 | { | 
|  | 1039 | const string_type __s(__f, __l); | 
|  | 1040 | string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); | 
|  | 1041 | switch (__d.size()) | 
|  | 1042 | { | 
|  | 1043 | case 1: | 
|  | 1044 | break; | 
|  | 1045 | case 12: | 
|  | 1046 | __d[11] = __d[3]; | 
|  | 1047 | break; | 
|  | 1048 | default: | 
|  | 1049 | __d.clear(); | 
|  | 1050 | break; | 
|  | 1051 | } | 
|  | 1052 | return __d; | 
|  | 1053 | } | 
|  | 1054 |  | 
|  | 1055 | template <class _CharT> | 
|  | 1056 | template <class _ForwardIterator> | 
|  | 1057 | typename regex_traits<_CharT>::string_type | 
|  | 1058 | regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, | 
|  | 1059 | _ForwardIterator __l, wchar_t) const | 
|  | 1060 | { | 
|  | 1061 | const string_type __s(__f, __l); | 
|  | 1062 | string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); | 
|  | 1063 | switch (__d.size()) | 
|  | 1064 | { | 
|  | 1065 | case 1: | 
|  | 1066 | break; | 
|  | 1067 | case 3: | 
|  | 1068 | __d[2] = __d[0]; | 
|  | 1069 | break; | 
|  | 1070 | default: | 
|  | 1071 | __d.clear(); | 
|  | 1072 | break; | 
|  | 1073 | } | 
|  | 1074 | return __d; | 
|  | 1075 | } | 
|  | 1076 |  | 
|  | 1077 | // lookup_collatename is very FreeBSD-specific | 
|  | 1078 |  | 
| Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1079 | string __get_collation_name(const char* __s); | 
| Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1080 |  | 
|  | 1081 | template <class _CharT> | 
|  | 1082 | template <class _ForwardIterator> | 
|  | 1083 | typename regex_traits<_CharT>::string_type | 
|  | 1084 | regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, | 
|  | 1085 | _ForwardIterator __l, char) const | 
|  | 1086 | { | 
|  | 1087 | string_type __s(__f, __l); | 
|  | 1088 | string_type __r; | 
|  | 1089 | if (!__s.empty()) | 
|  | 1090 | { | 
|  | 1091 | __r = __get_collation_name(__s.c_str()); | 
|  | 1092 | if (__r.empty() && __s.size() <= 2) | 
|  | 1093 | { | 
|  | 1094 | __r = __col_->transform(__s.data(), __s.data() + __s.size()); | 
|  | 1095 | if (__r.size() == 1 || __r.size() == 12) | 
|  | 1096 | __r = __s; | 
|  | 1097 | else | 
|  | 1098 | __r.clear(); | 
|  | 1099 | } | 
|  | 1100 | } | 
|  | 1101 | return __r; | 
|  | 1102 | } | 
|  | 1103 |  | 
|  | 1104 | template <class _CharT> | 
|  | 1105 | template <class _ForwardIterator> | 
|  | 1106 | typename regex_traits<_CharT>::string_type | 
|  | 1107 | regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, | 
|  | 1108 | _ForwardIterator __l, wchar_t) const | 
|  | 1109 | { | 
|  | 1110 | string_type __s(__f, __l); | 
|  | 1111 | string __n; | 
|  | 1112 | __n.reserve(__s.size()); | 
|  | 1113 | for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); | 
|  | 1114 | __i != __e; ++__i) | 
|  | 1115 | { | 
|  | 1116 | if (static_cast<unsigned>(*__i) >= 127) | 
|  | 1117 | return string_type(); | 
|  | 1118 | __n.push_back(char(*__i)); | 
|  | 1119 | } | 
|  | 1120 | string_type __r; | 
|  | 1121 | if (!__s.empty()) | 
|  | 1122 | { | 
|  | 1123 | __n = __get_collation_name(__n.c_str()); | 
|  | 1124 | if (!__n.empty()) | 
|  | 1125 | __r.assign(__n.begin(), __n.end()); | 
|  | 1126 | else if (__s.size() <= 2) | 
|  | 1127 | { | 
|  | 1128 | __r = __col_->transform(__s.data(), __s.data() + __s.size()); | 
|  | 1129 | if (__r.size() == 1 || __r.size() == 3) | 
|  | 1130 | __r = __s; | 
|  | 1131 | else | 
|  | 1132 | __r.clear(); | 
|  | 1133 | } | 
|  | 1134 | } | 
|  | 1135 | return __r; | 
|  | 1136 | } | 
|  | 1137 |  | 
| Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1138 | // lookup_classname | 
|  | 1139 |  | 
|  | 1140 | ctype_base::mask __get_classname(const char* __s, bool __icase); | 
|  | 1141 |  | 
|  | 1142 | template <class _CharT> | 
|  | 1143 | template <class _ForwardIterator> | 
|  | 1144 | typename regex_traits<_CharT>::char_class_type | 
|  | 1145 | regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, | 
|  | 1146 | _ForwardIterator __l, | 
|  | 1147 | bool __icase, char) const | 
|  | 1148 | { | 
|  | 1149 | string_type __s(__f, __l); | 
|  | 1150 | __ct_->tolower(&__s[0], &__s[0] + __s.size()); | 
|  | 1151 | return __get_classname(__s.c_str(), __icase); | 
|  | 1152 | } | 
|  | 1153 |  | 
|  | 1154 | template <class _CharT> | 
|  | 1155 | template <class _ForwardIterator> | 
|  | 1156 | typename regex_traits<_CharT>::char_class_type | 
|  | 1157 | regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, | 
|  | 1158 | _ForwardIterator __l, | 
|  | 1159 | bool __icase, wchar_t) const | 
|  | 1160 | { | 
|  | 1161 | string_type __s(__f, __l); | 
|  | 1162 | __ct_->tolower(&__s[0], &__s[0] + __s.size()); | 
|  | 1163 | string __n; | 
|  | 1164 | __n.reserve(__s.size()); | 
|  | 1165 | for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); | 
|  | 1166 | __i != __e; ++__i) | 
|  | 1167 | { | 
|  | 1168 | if (static_cast<unsigned>(*__i) >= 127) | 
|  | 1169 | return char_class_type(); | 
|  | 1170 | __n.push_back(char(*__i)); | 
|  | 1171 | } | 
|  | 1172 | return __get_classname(__n.c_str(), __icase); | 
|  | 1173 | } | 
|  | 1174 |  | 
|  | 1175 | template <class _CharT> | 
|  | 1176 | bool | 
|  | 1177 | regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const | 
|  | 1178 | { | 
|  | 1179 | if (__ct_->is(__m, __c)) | 
|  | 1180 | return true; | 
|  | 1181 | return (__c == '_' && (__m & __regex_word)); | 
|  | 1182 | } | 
|  | 1183 |  | 
|  | 1184 | template <class _CharT> | 
|  | 1185 | int | 
|  | 1186 | regex_traits<_CharT>::__value(unsigned char __ch, int __radix) | 
|  | 1187 | { | 
|  | 1188 | if ((__ch & 0xF8u) == 0x30)  // '0' <= __ch && __ch <= '7' | 
|  | 1189 | return __ch - '0'; | 
|  | 1190 | if (__radix != 8) | 
|  | 1191 | { | 
|  | 1192 | if ((__ch & 0xFEu) == 0x38)  // '8' <= __ch && __ch <= '9' | 
|  | 1193 | return __ch - '0'; | 
|  | 1194 | if (__radix == 16) | 
|  | 1195 | { | 
|  | 1196 | __ch |= 0x20;  // tolower | 
|  | 1197 | if ('a' <= __ch && __ch <= 'f') | 
| Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame^] | 1198 | return __ch - ('a' - 10); | 
| Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1199 | } | 
|  | 1200 | } | 
|  | 1201 | return -1; | 
|  | 1202 | } | 
|  | 1203 |  | 
|  | 1204 | template <class _CharT> | 
|  | 1205 | inline | 
|  | 1206 | int | 
|  | 1207 | regex_traits<_CharT>::__value(wchar_t __ch, int __radix) const | 
|  | 1208 | { | 
|  | 1209 | return __value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix); | 
|  | 1210 | } | 
|  | 1211 |  | 
| Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame^] | 1212 | template <class _CharT, class _Traits = regex_traits<_CharT> > | 
|  | 1213 | class basic_regex | 
|  | 1214 | { | 
|  | 1215 | public: | 
|  | 1216 | // types: | 
|  | 1217 | typedef _CharT                              value_type; | 
|  | 1218 | typedef regex_constants::syntax_option_type flag_type; | 
|  | 1219 | typedef typename _Traits::locale_type       locale_type; | 
|  | 1220 |  | 
|  | 1221 | private: | 
|  | 1222 | _Traits   __traits_; | 
|  | 1223 | flag_type __flags_; | 
|  | 1224 | unsigned __marked_count_; | 
|  | 1225 |  | 
|  | 1226 | public: | 
|  | 1227 | // constants: | 
|  | 1228 | static const/*expr*/ regex_constants::syntax_option_type icase = regex_constants::icase; | 
|  | 1229 | static const/*expr*/ regex_constants::syntax_option_type nosubs = regex_constants::nosubs; | 
|  | 1230 | static const/*expr*/ regex_constants::syntax_option_type optimize = regex_constants::optimize; | 
|  | 1231 | static const/*expr*/ regex_constants::syntax_option_type collate = regex_constants::collate; | 
|  | 1232 | static const/*expr*/ regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript; | 
|  | 1233 | static const/*expr*/ regex_constants::syntax_option_type basic = regex_constants::basic; | 
|  | 1234 | static const/*expr*/ regex_constants::syntax_option_type extended = regex_constants::extended; | 
|  | 1235 | static const/*expr*/ regex_constants::syntax_option_type awk = regex_constants::awk; | 
|  | 1236 | static const/*expr*/ regex_constants::syntax_option_type grep = regex_constants::grep; | 
|  | 1237 | static const/*expr*/ regex_constants::syntax_option_type egrep = regex_constants::egrep; | 
|  | 1238 |  | 
|  | 1239 | // construct/copy/destroy: | 
|  | 1240 | basic_regex(); | 
|  | 1241 | explicit basic_regex(const value_type* __p, flag_type __f = regex_constants::ECMAScript) | 
|  | 1242 | : __flags_(__f), __marked_count_(0) | 
|  | 1243 | {__parse(__p, __p + __traits_.length(__p));} | 
|  | 1244 | basic_regex(const value_type* __p, size_t __len, flag_type __f) | 
|  | 1245 | : __flags_(__f), __marked_count_(0) | 
|  | 1246 | {__parse(__p, __p + __len);} | 
|  | 1247 | basic_regex(const basic_regex&); | 
|  | 1248 | #ifdef _LIBCPP_MOVE | 
|  | 1249 | basic_regex(basic_regex&&); | 
|  | 1250 | #endif | 
|  | 1251 | template <class _ST, class _SA> | 
|  | 1252 | explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p, | 
|  | 1253 | flag_type __f = regex_constants::ECMAScript) | 
|  | 1254 | : __flags_(__f), __marked_count_(0) | 
|  | 1255 | {__parse(__p.begin(), __p.end());} | 
|  | 1256 | template <class _ForwardIterator> | 
|  | 1257 | basic_regex(_ForwardIterator __first, _ForwardIterator __last, | 
|  | 1258 | flag_type __f = regex_constants::ECMAScript) | 
|  | 1259 | : __flags_(__f), __marked_count_(0) | 
|  | 1260 | {__parse(__first, __last);} | 
|  | 1261 | basic_regex(initializer_list<value_type> __il, | 
|  | 1262 | flag_type __f = regex_constants::ECMAScript) | 
|  | 1263 | : __flags_(__f), __marked_count_(0) | 
|  | 1264 | {__parse(__il.begin(), __il.end());} | 
|  | 1265 |  | 
|  | 1266 | ~basic_regex(); | 
|  | 1267 |  | 
|  | 1268 | basic_regex& operator=(const basic_regex&); | 
|  | 1269 | #ifdef _LIBCPP_MOVE | 
|  | 1270 | basic_regex& operator=(basic_regex&&); | 
|  | 1271 | #endif | 
|  | 1272 | basic_regex& operator=(const value_type* __p); | 
|  | 1273 | basic_regex& operator=(initializer_list<value_type> __il); | 
|  | 1274 | template <class _ST, class _SA> | 
|  | 1275 | basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p); | 
|  | 1276 |  | 
|  | 1277 | // assign: | 
|  | 1278 | basic_regex& assign(const basic_regex& __that); | 
|  | 1279 | #ifdef _LIBCPP_MOVE | 
|  | 1280 | basic_regex& assign(basic_regex&& __that); | 
|  | 1281 | #endif | 
|  | 1282 | basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript); | 
|  | 1283 | basic_regex& assign(const value_type* __p, size_t __len, flag_type __f); | 
|  | 1284 | template <class _ST, class _SA> | 
|  | 1285 | basic_regex& assign(const basic_string<value_type, _ST, _SA>& __s, | 
|  | 1286 | flag_type __f = regex_constants::ECMAScript); | 
|  | 1287 | template <class _InputIterator> | 
|  | 1288 | basic_regex& assign(_InputIterator __first, _InputIterator __last, | 
|  | 1289 | flag_type __f = regex_constants::ECMAScript); | 
|  | 1290 | basic_regex& assign(initializer_list<value_type> __il, | 
|  | 1291 | flag_type = regex_constants::ECMAScript); | 
|  | 1292 |  | 
|  | 1293 | // const operations: | 
|  | 1294 | unsigned mark_count() const {return __marked_count_;} | 
|  | 1295 | flag_type flags() const {return __flags_;} | 
|  | 1296 |  | 
|  | 1297 | // locale: | 
|  | 1298 | locale_type imbue(locale_type __loc) {return __traits_.imbue(__loc);} | 
|  | 1299 | locale_type getloc() const {return __traits_.getloc();} | 
|  | 1300 |  | 
|  | 1301 | // swap: | 
|  | 1302 | void swap(basic_regex&); | 
|  | 1303 |  | 
|  | 1304 | private: | 
|  | 1305 | template <class _ForwardIterator> | 
|  | 1306 | void __parse(_ForwardIterator __first, _ForwardIterator __last); | 
|  | 1307 | template <class _ForwardIterator> | 
|  | 1308 | _ForwardIterator | 
|  | 1309 | __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last); | 
|  | 1310 | template <class _ForwardIterator> | 
|  | 1311 | _ForwardIterator | 
|  | 1312 | __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last); | 
|  | 1313 | template <class _ForwardIterator> | 
|  | 1314 | _ForwardIterator | 
|  | 1315 | __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last); | 
|  | 1316 | template <class _ForwardIterator> | 
|  | 1317 | _ForwardIterator | 
|  | 1318 | __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last); | 
|  | 1319 | template <class _ForwardIterator> | 
|  | 1320 | _ForwardIterator | 
|  | 1321 | __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last); | 
|  | 1322 | template <class _ForwardIterator> | 
|  | 1323 | _ForwardIterator | 
|  | 1324 | __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last); | 
|  | 1325 | template <class _ForwardIterator> | 
|  | 1326 | _ForwardIterator | 
|  | 1327 | __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last); | 
|  | 1328 | template <class _ForwardIterator> | 
|  | 1329 | _ForwardIterator | 
|  | 1330 | __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last); | 
|  | 1331 | template <class _ForwardIterator> | 
|  | 1332 | _ForwardIterator | 
|  | 1333 | __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last); | 
|  | 1334 | template <class _ForwardIterator> | 
|  | 1335 | _ForwardIterator | 
|  | 1336 | __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last); | 
|  | 1337 | template <class _ForwardIterator> | 
|  | 1338 | _ForwardIterator | 
|  | 1339 | __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last); | 
|  | 1340 | template <class _ForwardIterator> | 
|  | 1341 | _ForwardIterator | 
|  | 1342 | __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last); | 
|  | 1343 | template <class _ForwardIterator> | 
|  | 1344 | _ForwardIterator | 
|  | 1345 | __parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last); | 
|  | 1346 |  | 
|  | 1347 | void __push_l_anchor(); | 
|  | 1348 | void __push_r_anchor(); | 
|  | 1349 | void __push_match_any(); | 
|  | 1350 | void __push_greedy_inf_repeat(int __min); | 
|  | 1351 | void __push_exact_repeat(int __count); | 
|  | 1352 | void __push_repeat(int __min, int __max); | 
|  | 1353 | }; | 
|  | 1354 |  | 
|  | 1355 | template <class _CharT, class _Traits> | 
|  | 1356 | inline | 
|  | 1357 | basic_regex<_CharT, _Traits>::basic_regex() | 
|  | 1358 | : __traits_(), __flags_(), __marked_count_(0) | 
|  | 1359 | { | 
|  | 1360 | } | 
|  | 1361 |  | 
|  | 1362 | template <class _CharT, class _Traits> | 
|  | 1363 | basic_regex<_CharT, _Traits>::~basic_regex() | 
|  | 1364 | { | 
|  | 1365 | } | 
|  | 1366 |  | 
|  | 1367 | template <class _CharT, class _Traits> | 
|  | 1368 | template <class _ForwardIterator> | 
|  | 1369 | void | 
|  | 1370 | basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first, | 
|  | 1371 | _ForwardIterator __last) | 
|  | 1372 | { | 
|  | 1373 | switch (__flags_ & 0x3F0) | 
|  | 1374 | { | 
|  | 1375 | case ECMAScript: | 
|  | 1376 | break; | 
|  | 1377 | case basic: | 
|  | 1378 | __parse_basic_reg_exp(__first, __last); | 
|  | 1379 | break; | 
|  | 1380 | case extended: | 
|  | 1381 | break; | 
|  | 1382 | case awk: | 
|  | 1383 | break; | 
|  | 1384 | case grep: | 
|  | 1385 | break; | 
|  | 1386 | case egrep: | 
|  | 1387 | break; | 
|  | 1388 | default: | 
|  | 1389 | throw regex_error(regex_constants::error_temp); | 
|  | 1390 | } | 
|  | 1391 | } | 
|  | 1392 |  | 
|  | 1393 | template <class _CharT, class _Traits> | 
|  | 1394 | template <class _ForwardIterator> | 
|  | 1395 | _ForwardIterator | 
|  | 1396 | basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first, | 
|  | 1397 | _ForwardIterator __last) | 
|  | 1398 | { | 
|  | 1399 | if (__first != __last) | 
|  | 1400 | { | 
|  | 1401 | if (*__first == '^') | 
|  | 1402 | { | 
|  | 1403 | __push_l_anchor(); | 
|  | 1404 | ++__first; | 
|  | 1405 | } | 
|  | 1406 | if (__first != __last) | 
|  | 1407 | { | 
|  | 1408 | __first = __parse_RE_expression(__first, __last); | 
|  | 1409 | if (__first != __last) | 
|  | 1410 | { | 
|  | 1411 | _ForwardIterator __temp = next(__first); | 
|  | 1412 | if (__temp == __last && *__first == '$') | 
|  | 1413 | { | 
|  | 1414 | __push_r_anchor(); | 
|  | 1415 | ++__first; | 
|  | 1416 | } | 
|  | 1417 | } | 
|  | 1418 | } | 
|  | 1419 | if (__first != __last) | 
|  | 1420 | throw regex_error(regex_constants::error_temp); | 
|  | 1421 | } | 
|  | 1422 | return __first; | 
|  | 1423 | } | 
|  | 1424 |  | 
|  | 1425 | template <class _CharT, class _Traits> | 
|  | 1426 | template <class _ForwardIterator> | 
|  | 1427 | _ForwardIterator | 
|  | 1428 | basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first, | 
|  | 1429 | _ForwardIterator __last) | 
|  | 1430 | { | 
|  | 1431 | while (true) | 
|  | 1432 | { | 
|  | 1433 | _ForwardIterator __temp = __parse_simple_RE(__first, __last); | 
|  | 1434 | if (__temp == __first) | 
|  | 1435 | break; | 
|  | 1436 | __first = __temp; | 
|  | 1437 | } | 
|  | 1438 | return __first; | 
|  | 1439 | } | 
|  | 1440 |  | 
|  | 1441 | template <class _CharT, class _Traits> | 
|  | 1442 | template <class _ForwardIterator> | 
|  | 1443 | _ForwardIterator | 
|  | 1444 | basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first, | 
|  | 1445 | _ForwardIterator __last) | 
|  | 1446 | { | 
|  | 1447 | if (__first != __last) | 
|  | 1448 | { | 
|  | 1449 | _ForwardIterator __temp = __parse_nondupl_RE(__first, __last); | 
|  | 1450 | if (__temp != __first) | 
|  | 1451 | { | 
|  | 1452 | __first = __temp; | 
|  | 1453 | __first = __parse_RE_dupl_symbol(__first, __last); | 
|  | 1454 | } | 
|  | 1455 | } | 
|  | 1456 | return __first; | 
|  | 1457 | } | 
|  | 1458 |  | 
|  | 1459 | template <class _CharT, class _Traits> | 
|  | 1460 | template <class _ForwardIterator> | 
|  | 1461 | _ForwardIterator | 
|  | 1462 | basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first, | 
|  | 1463 | _ForwardIterator __last) | 
|  | 1464 | { | 
|  | 1465 | _ForwardIterator __temp = __first; | 
|  | 1466 | __first = __parse_one_char_or_coll_elem_RE(__first, __last); | 
|  | 1467 | if (__temp == __first) | 
|  | 1468 | { | 
|  | 1469 | __temp = __parse_Back_open_paren(__first, __last); | 
|  | 1470 | if (__temp != __first) | 
|  | 1471 | { | 
|  | 1472 | __first = __parse_RE_expression(__temp, __last); | 
|  | 1473 | __temp = __parse_Back_close_paren(__first, __last); | 
|  | 1474 | if (__temp == __first) | 
|  | 1475 | throw regex_error(regex_constants::error_paren); | 
|  | 1476 | __first = __temp; | 
|  | 1477 | ++__marked_count_; | 
|  | 1478 | } | 
|  | 1479 | else | 
|  | 1480 | __first = __parse_BACKREF(__first, __last); | 
|  | 1481 | } | 
|  | 1482 | return __first; | 
|  | 1483 | } | 
|  | 1484 |  | 
|  | 1485 | template <class _CharT, class _Traits> | 
|  | 1486 | template <class _ForwardIterator> | 
|  | 1487 | _ForwardIterator | 
|  | 1488 | basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE( | 
|  | 1489 | _ForwardIterator __first, | 
|  | 1490 | _ForwardIterator __last) | 
|  | 1491 | { | 
|  | 1492 | _ForwardIterator __temp = __first; | 
|  | 1493 | __first = __parse_ORD_CHAR(__first, __last); | 
|  | 1494 | if (__temp == __first) | 
|  | 1495 | { | 
|  | 1496 | __first = __parse_QUOTED_CHAR(__first, __last); | 
|  | 1497 | if (__temp == __first) | 
|  | 1498 | { | 
|  | 1499 | if (__first != __last && *__first == '.') | 
|  | 1500 | { | 
|  | 1501 | __push_match_any(); | 
|  | 1502 | ++__first; | 
|  | 1503 | } | 
|  | 1504 | else | 
|  | 1505 | __first = __parse_bracket_expression(__first, __last); | 
|  | 1506 | } | 
|  | 1507 | } | 
|  | 1508 | return __first; | 
|  | 1509 | } | 
|  | 1510 |  | 
|  | 1511 | template <class _CharT, class _Traits> | 
|  | 1512 | template <class _ForwardIterator> | 
|  | 1513 | _ForwardIterator | 
|  | 1514 | basic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first, | 
|  | 1515 | _ForwardIterator __last) | 
|  | 1516 | { | 
|  | 1517 | if (__first != __last) | 
|  | 1518 | { | 
|  | 1519 | _ForwardIterator __temp = next(__first); | 
|  | 1520 | if (__temp != __last) | 
|  | 1521 | { | 
|  | 1522 | if (*__first == '\\' && *__temp == '(') | 
|  | 1523 | __first = ++__temp; | 
|  | 1524 | } | 
|  | 1525 | } | 
|  | 1526 | return __first; | 
|  | 1527 | } | 
|  | 1528 |  | 
|  | 1529 | template <class _CharT, class _Traits> | 
|  | 1530 | template <class _ForwardIterator> | 
|  | 1531 | _ForwardIterator | 
|  | 1532 | basic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first, | 
|  | 1533 | _ForwardIterator __last) | 
|  | 1534 | { | 
|  | 1535 | if (__first != __last) | 
|  | 1536 | { | 
|  | 1537 | _ForwardIterator __temp = next(__first); | 
|  | 1538 | if (__temp != __last) | 
|  | 1539 | { | 
|  | 1540 | if (*__first == '\\' && *__temp == ')') | 
|  | 1541 | __first = ++__temp; | 
|  | 1542 | } | 
|  | 1543 | } | 
|  | 1544 | return __first; | 
|  | 1545 | } | 
|  | 1546 |  | 
|  | 1547 | template <class _CharT, class _Traits> | 
|  | 1548 | template <class _ForwardIterator> | 
|  | 1549 | _ForwardIterator | 
|  | 1550 | basic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first, | 
|  | 1551 | _ForwardIterator __last) | 
|  | 1552 | { | 
|  | 1553 | if (__first != __last) | 
|  | 1554 | { | 
|  | 1555 | _ForwardIterator __temp = next(__first); | 
|  | 1556 | if (__temp != __last) | 
|  | 1557 | { | 
|  | 1558 | if (*__first == '\\' && *__temp == '{') | 
|  | 1559 | __first = ++__temp; | 
|  | 1560 | } | 
|  | 1561 | } | 
|  | 1562 | return __first; | 
|  | 1563 | } | 
|  | 1564 |  | 
|  | 1565 | template <class _CharT, class _Traits> | 
|  | 1566 | template <class _ForwardIterator> | 
|  | 1567 | _ForwardIterator | 
|  | 1568 | basic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first, | 
|  | 1569 | _ForwardIterator __last) | 
|  | 1570 | { | 
|  | 1571 | if (__first != __last) | 
|  | 1572 | { | 
|  | 1573 | _ForwardIterator __temp = next(__first); | 
|  | 1574 | if (__temp != __last) | 
|  | 1575 | { | 
|  | 1576 | if (*__first == '\\' && *__temp == '}') | 
|  | 1577 | __first = ++__temp; | 
|  | 1578 | } | 
|  | 1579 | } | 
|  | 1580 | return __first; | 
|  | 1581 | } | 
|  | 1582 |  | 
|  | 1583 | template <class _CharT, class _Traits> | 
|  | 1584 | template <class _ForwardIterator> | 
|  | 1585 | _ForwardIterator | 
|  | 1586 | basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first, | 
|  | 1587 | _ForwardIterator __last) | 
|  | 1588 | { | 
|  | 1589 | if (__first != __last) | 
|  | 1590 | { | 
|  | 1591 | _ForwardIterator __temp = next(__first); | 
|  | 1592 | if (__temp != __last) | 
|  | 1593 | { | 
|  | 1594 | if (*__first == '\\' && '1' <= *__temp && *__temp <= '9') | 
|  | 1595 | { | 
|  | 1596 | __push_back_ref(*__temp - '0'); | 
|  | 1597 | __first = ++__temp; | 
|  | 1598 | } | 
|  | 1599 | } | 
|  | 1600 | } | 
|  | 1601 | return __first; | 
|  | 1602 | } | 
|  | 1603 |  | 
|  | 1604 | template <class _CharT, class _Traits> | 
|  | 1605 | template <class _ForwardIterator> | 
|  | 1606 | _ForwardIterator | 
|  | 1607 | basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first, | 
|  | 1608 | _ForwardIterator __last) | 
|  | 1609 | { | 
|  | 1610 | if (__first != __last) | 
|  | 1611 | { | 
|  | 1612 | _ForwardIterator __temp = next(__first); | 
|  | 1613 | if (__temp == __last && *__first == '$') | 
|  | 1614 | return __first; | 
|  | 1615 | // Not called inside a bracket | 
|  | 1616 | if (*__first == '.' || *__first == '\\' || *__first == '[') | 
|  | 1617 | return __first; | 
|  | 1618 | __push_ord_char(*__first); | 
|  | 1619 | ++__first; | 
|  | 1620 | } | 
|  | 1621 | return __first; | 
|  | 1622 | } | 
|  | 1623 |  | 
|  | 1624 | template <class _CharT, class _Traits> | 
|  | 1625 | template <class _ForwardIterator> | 
|  | 1626 | _ForwardIterator | 
|  | 1627 | basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first, | 
|  | 1628 | _ForwardIterator __last) | 
|  | 1629 | { | 
|  | 1630 | if (__first != __last) | 
|  | 1631 | { | 
|  | 1632 | _ForwardIterator __temp = next(__first); | 
|  | 1633 | if (__temp != __last) | 
|  | 1634 | { | 
|  | 1635 | if (*__first == '\\') | 
|  | 1636 | { | 
|  | 1637 | switch (*__temp) | 
|  | 1638 | { | 
|  | 1639 | case '^': | 
|  | 1640 | case '.': | 
|  | 1641 | case '*': | 
|  | 1642 | case '[': | 
|  | 1643 | case '$': | 
|  | 1644 | case '\\': | 
|  | 1645 | __push_ord_char(*__temp); | 
|  | 1646 | __first = ++__temp; | 
|  | 1647 | break; | 
|  | 1648 | } | 
|  | 1649 | } | 
|  | 1650 | } | 
|  | 1651 | } | 
|  | 1652 | return __first; | 
|  | 1653 | } | 
|  | 1654 |  | 
|  | 1655 | template <class _CharT, class _Traits> | 
|  | 1656 | template <class _ForwardIterator> | 
|  | 1657 | _ForwardIterator | 
|  | 1658 | basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first, | 
|  | 1659 | _ForwardIterator __last) | 
|  | 1660 | { | 
|  | 1661 | if (__first != __last) | 
|  | 1662 | { | 
|  | 1663 | if (__first == '*') | 
|  | 1664 | { | 
|  | 1665 | __push_greedy_inf_repeat(0); | 
|  | 1666 | ++__first; | 
|  | 1667 | } | 
|  | 1668 | else | 
|  | 1669 | { | 
|  | 1670 | _ForwardIterator __temp = __parse_Back_open_brace(__first, __last); | 
|  | 1671 | if (__temp != __first) | 
|  | 1672 | { | 
|  | 1673 | int __min = 0; | 
|  | 1674 | __first = __temp; | 
|  | 1675 | __temp = __parse_DUP_COUNT(__first, __last, __min); | 
|  | 1676 | if (__temp == __first) | 
|  | 1677 | throw regex_error(regex_constants::error_badbrace); | 
|  | 1678 | __first = __temp; | 
|  | 1679 | if (__first == __last) | 
|  | 1680 | throw regex_error(regex_constants::error_brace); | 
|  | 1681 | if (*__first != ',') | 
|  | 1682 | { | 
|  | 1683 | __temp = __parse_Back_close_brace(__first, __last); | 
|  | 1684 | if (__temp == __first) | 
|  | 1685 | throw regex_error(regex_constants::error_brace); | 
|  | 1686 | __push_exact_repeat(__min); | 
|  | 1687 | __first = __temp; | 
|  | 1688 | } | 
|  | 1689 | else | 
|  | 1690 | { | 
|  | 1691 | ++__first;  // consume ',' | 
|  | 1692 | int __max = -1; | 
|  | 1693 | __first = __parse_DUP_COUNT(__first, __last, __max); | 
|  | 1694 | __temp = __parse_Back_close_brace(__first, __last); | 
|  | 1695 | if (__temp == __first) | 
|  | 1696 | throw regex_error(regex_constants::error_brace); | 
|  | 1697 | if (__max == -1) | 
|  | 1698 | __push_greedy_inf_repeat(__min); | 
|  | 1699 | else | 
|  | 1700 | { | 
|  | 1701 | if (__max < __min) | 
|  | 1702 | throw regex_error(regex_constants::error_badbrace); | 
|  | 1703 | __push_repeat(__min, __max); | 
|  | 1704 | } | 
|  | 1705 | __first = __temp; | 
|  | 1706 | } | 
|  | 1707 | } | 
|  | 1708 | } | 
|  | 1709 | } | 
|  | 1710 | return __first; | 
|  | 1711 | } | 
|  | 1712 |  | 
|  | 1713 | typedef basic_regex<char>    regex; | 
|  | 1714 | typedef basic_regex<wchar_t> wregex; | 
|  | 1715 |  | 
| Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1716 | _LIBCPP_END_NAMESPACE_STD | 
|  | 1717 |  | 
|  | 1718 | #endif  // _LIBCPP_REGEX |