| 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> | 
|  | 723 |  | 
|  | 724 | #pragma GCC system_header | 
|  | 725 |  | 
|  | 726 | _LIBCPP_BEGIN_NAMESPACE_STD | 
|  | 727 |  | 
|  | 728 | namespace regex_constants | 
|  | 729 | { | 
|  | 730 |  | 
|  | 731 | // syntax_option_type | 
|  | 732 |  | 
|  | 733 | enum syntax_option_type | 
|  | 734 | { | 
|  | 735 | icase      = 1 << 0, | 
|  | 736 | nosubs     = 1 << 1, | 
|  | 737 | optimize   = 1 << 2, | 
|  | 738 | collate    = 1 << 3, | 
|  | 739 | ECMAScript = 1 << 4, | 
|  | 740 | basic      = 1 << 5, | 
|  | 741 | extended   = 1 << 6, | 
|  | 742 | awk        = 1 << 7, | 
|  | 743 | grep       = 1 << 8, | 
|  | 744 | egrep      = 1 << 9 | 
|  | 745 | }; | 
|  | 746 |  | 
|  | 747 | inline | 
|  | 748 | /*constexpr*/ | 
|  | 749 | syntax_option_type | 
|  | 750 | operator~(syntax_option_type __x) | 
|  | 751 | { | 
|  | 752 | return syntax_option_type(~int(__x)); | 
|  | 753 | } | 
|  | 754 |  | 
|  | 755 | inline | 
|  | 756 | /*constexpr*/ | 
|  | 757 | syntax_option_type | 
|  | 758 | operator&(syntax_option_type __x, syntax_option_type __y) | 
|  | 759 | { | 
|  | 760 | return syntax_option_type(int(__x) & int(__y)); | 
|  | 761 | } | 
|  | 762 |  | 
|  | 763 | inline | 
|  | 764 | /*constexpr*/ | 
|  | 765 | syntax_option_type | 
|  | 766 | operator|(syntax_option_type __x, syntax_option_type __y) | 
|  | 767 | { | 
|  | 768 | return syntax_option_type(int(__x) | int(__y)); | 
|  | 769 | } | 
|  | 770 |  | 
|  | 771 | inline | 
|  | 772 | /*constexpr*/ | 
|  | 773 | syntax_option_type | 
|  | 774 | operator^(syntax_option_type __x, syntax_option_type __y) | 
|  | 775 | { | 
|  | 776 | return syntax_option_type(int(__x) ^ int(__y)); | 
|  | 777 | } | 
|  | 778 |  | 
|  | 779 | inline | 
|  | 780 | /*constexpr*/ | 
|  | 781 | syntax_option_type& | 
|  | 782 | operator&=(syntax_option_type& __x, syntax_option_type __y) | 
|  | 783 | { | 
|  | 784 | __x = __x & __y; | 
|  | 785 | return __x; | 
|  | 786 | } | 
|  | 787 |  | 
|  | 788 | inline | 
|  | 789 | /*constexpr*/ | 
|  | 790 | syntax_option_type& | 
|  | 791 | operator|=(syntax_option_type& __x, syntax_option_type __y) | 
|  | 792 | { | 
|  | 793 | __x = __x | __y; | 
|  | 794 | return __x; | 
|  | 795 | } | 
|  | 796 |  | 
|  | 797 | inline | 
|  | 798 | /*constexpr*/ | 
|  | 799 | syntax_option_type& | 
|  | 800 | operator^=(syntax_option_type& __x, syntax_option_type __y) | 
|  | 801 | { | 
|  | 802 | __x = __x ^ __y; | 
|  | 803 | return __x; | 
|  | 804 | } | 
|  | 805 |  | 
|  | 806 | // match_flag_type | 
|  | 807 |  | 
|  | 808 | enum match_flag_type | 
|  | 809 | { | 
|  | 810 | match_default     = 0, | 
|  | 811 | match_not_bol     = 1 << 0, | 
|  | 812 | match_not_eol     = 1 << 1, | 
|  | 813 | match_not_bow     = 1 << 2, | 
|  | 814 | match_not_eow     = 1 << 3, | 
|  | 815 | match_any         = 1 << 4, | 
|  | 816 | match_not_null    = 1 << 5, | 
|  | 817 | match_continuous  = 1 << 6, | 
|  | 818 | match_prev_avail  = 1 << 7, | 
|  | 819 | format_default    = 0, | 
|  | 820 | format_sed        = 1 << 8, | 
|  | 821 | format_no_copy    = 1 << 9, | 
|  | 822 | format_first_only = 1 << 10 | 
|  | 823 | }; | 
|  | 824 |  | 
|  | 825 | inline | 
|  | 826 | /*constexpr*/ | 
|  | 827 | match_flag_type | 
|  | 828 | operator~(match_flag_type __x) | 
|  | 829 | { | 
|  | 830 | return match_flag_type(~int(__x)); | 
|  | 831 | } | 
|  | 832 |  | 
|  | 833 | inline | 
|  | 834 | /*constexpr*/ | 
|  | 835 | match_flag_type | 
|  | 836 | operator&(match_flag_type __x, match_flag_type __y) | 
|  | 837 | { | 
|  | 838 | return match_flag_type(int(__x) & int(__y)); | 
|  | 839 | } | 
|  | 840 |  | 
|  | 841 | inline | 
|  | 842 | /*constexpr*/ | 
|  | 843 | match_flag_type | 
|  | 844 | operator|(match_flag_type __x, match_flag_type __y) | 
|  | 845 | { | 
|  | 846 | return match_flag_type(int(__x) | int(__y)); | 
|  | 847 | } | 
|  | 848 |  | 
|  | 849 | inline | 
|  | 850 | /*constexpr*/ | 
|  | 851 | match_flag_type | 
|  | 852 | operator^(match_flag_type __x, match_flag_type __y) | 
|  | 853 | { | 
|  | 854 | return match_flag_type(int(__x) ^ int(__y)); | 
|  | 855 | } | 
|  | 856 |  | 
|  | 857 | inline | 
|  | 858 | /*constexpr*/ | 
|  | 859 | match_flag_type& | 
|  | 860 | operator&=(match_flag_type& __x, match_flag_type __y) | 
|  | 861 | { | 
|  | 862 | __x = __x & __y; | 
|  | 863 | return __x; | 
|  | 864 | } | 
|  | 865 |  | 
|  | 866 | inline | 
|  | 867 | /*constexpr*/ | 
|  | 868 | match_flag_type& | 
|  | 869 | operator|=(match_flag_type& __x, match_flag_type __y) | 
|  | 870 | { | 
|  | 871 | __x = __x | __y; | 
|  | 872 | return __x; | 
|  | 873 | } | 
|  | 874 |  | 
|  | 875 | inline | 
|  | 876 | /*constexpr*/ | 
|  | 877 | match_flag_type& | 
|  | 878 | operator^=(match_flag_type& __x, match_flag_type __y) | 
|  | 879 | { | 
|  | 880 | __x = __x ^ __y; | 
|  | 881 | return __x; | 
|  | 882 | } | 
|  | 883 |  | 
|  | 884 | enum error_type | 
|  | 885 | { | 
|  | 886 | error_collate = 1, | 
|  | 887 | error_ctype, | 
|  | 888 | error_escape, | 
|  | 889 | error_backref, | 
|  | 890 | error_brack, | 
|  | 891 | error_paren, | 
|  | 892 | error_brace, | 
|  | 893 | error_badbrace, | 
|  | 894 | error_range, | 
|  | 895 | error_space, | 
|  | 896 | error_badrepeat, | 
|  | 897 | error_complexity, | 
|  | 898 | error_stack | 
|  | 899 | }; | 
|  | 900 |  | 
|  | 901 | }  // regex_constants | 
|  | 902 |  | 
|  | 903 | class _LIBCPP_EXCEPTION_ABI regex_error | 
|  | 904 | : public runtime_error | 
|  | 905 | { | 
|  | 906 | regex_constants::error_type __code_; | 
|  | 907 | public: | 
|  | 908 | explicit regex_error(regex_constants::error_type __ecode); | 
|  | 909 | virtual ~regex_error() throw(); | 
|  | 910 | regex_constants::error_type code() const {return __code_;} | 
|  | 911 | }; | 
|  | 912 |  | 
|  | 913 | template <class _CharT> | 
|  | 914 | struct regex_traits | 
|  | 915 | { | 
|  | 916 | public: | 
|  | 917 | typedef _CharT                  char_type; | 
|  | 918 | typedef basic_string<char_type> string_type; | 
|  | 919 | typedef locale                  locale_type; | 
| Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame^] | 920 | typedef ctype_base::mask        char_class_type; | 
| Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 921 |  | 
| Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame^] | 922 | static const char_class_type __regex_word = 0x80; | 
| Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 923 | private: | 
|  | 924 | locale __loc_; | 
|  | 925 | const ctype<char_type>* __ct_; | 
|  | 926 | const collate<char_type>* __col_; | 
|  | 927 |  | 
|  | 928 | public: | 
|  | 929 | regex_traits(); | 
|  | 930 |  | 
|  | 931 | static size_t length(const char_type* __p) | 
|  | 932 | {return char_traits<char_type>::length(__p);} | 
|  | 933 | char_type translate(char_type __c) const {return __c;} | 
|  | 934 | char_type translate_nocase(char_type __c) const; | 
|  | 935 | template <class _ForwardIterator> | 
|  | 936 | string_type | 
|  | 937 | transform(_ForwardIterator __f, _ForwardIterator __l) const; | 
|  | 938 | template <class _ForwardIterator> | 
|  | 939 | string_type | 
|  | 940 | transform_primary( _ForwardIterator __f, _ForwardIterator __l) const | 
|  | 941 | {return __transform_primary(__f, __l, char_type());} | 
|  | 942 | template <class _ForwardIterator> | 
|  | 943 | string_type | 
|  | 944 | lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const | 
|  | 945 | {return __lookup_collatename(__f, __l, char_type());} | 
|  | 946 | template <class _ForwardIterator> | 
|  | 947 | char_class_type | 
|  | 948 | lookup_classname(_ForwardIterator __f, _ForwardIterator __l, | 
| Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame^] | 949 | bool __icase = false) const | 
|  | 950 | {return __lookup_classname(__f, __l, __icase, char_type());} | 
|  | 951 | bool isctype(char_type __c, char_class_type __m) const; | 
|  | 952 | int value(char_type __ch, int __radix) const | 
|  | 953 | {return __value(__ch, __radix);} | 
| Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 954 | locale_type imbue(locale_type __l); | 
|  | 955 | locale_type getloc()const {return __loc_;} | 
|  | 956 |  | 
|  | 957 | private: | 
|  | 958 | void __init(); | 
|  | 959 |  | 
|  | 960 | template <class _ForwardIterator> | 
|  | 961 | string_type | 
|  | 962 | __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const; | 
|  | 963 | template <class _ForwardIterator> | 
|  | 964 | string_type | 
|  | 965 | __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; | 
|  | 966 |  | 
|  | 967 | template <class _ForwardIterator> | 
|  | 968 | string_type | 
|  | 969 | __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const; | 
|  | 970 | template <class _ForwardIterator> | 
|  | 971 | string_type | 
|  | 972 | __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; | 
| Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame^] | 973 |  | 
|  | 974 | template <class _ForwardIterator> | 
|  | 975 | char_class_type | 
|  | 976 | __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, | 
|  | 977 | bool __icase, char) const; | 
|  | 978 | template <class _ForwardIterator> | 
|  | 979 | char_class_type | 
|  | 980 | __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, | 
|  | 981 | bool __icase, wchar_t) const; | 
|  | 982 |  | 
|  | 983 | static int __value(unsigned char __ch, int __radix); | 
|  | 984 | int __value(char __ch, int __radix) const | 
|  | 985 | {return __value(static_cast<unsigned char>(__ch), __radix);} | 
|  | 986 | int __value(wchar_t __ch, int __radix) const; | 
| Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 987 | }; | 
|  | 988 |  | 
|  | 989 | template <class _CharT> | 
|  | 990 | regex_traits<_CharT>::regex_traits() | 
|  | 991 | { | 
|  | 992 | __init(); | 
|  | 993 | } | 
|  | 994 |  | 
|  | 995 | template <class _CharT> | 
|  | 996 | typename regex_traits<_CharT>::char_type | 
|  | 997 | regex_traits<_CharT>::translate_nocase(char_type __c) const | 
|  | 998 | { | 
|  | 999 | return __ct_->tolower(__c); | 
|  | 1000 | } | 
|  | 1001 |  | 
|  | 1002 | template <class _CharT> | 
|  | 1003 | template <class _ForwardIterator> | 
|  | 1004 | typename regex_traits<_CharT>::string_type | 
|  | 1005 | regex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const | 
|  | 1006 | { | 
|  | 1007 | string_type __s(__f, __l); | 
|  | 1008 | return __col_->transform(__s.data(), __s.data() + __s.size()); | 
|  | 1009 | } | 
|  | 1010 |  | 
|  | 1011 | template <class _CharT> | 
|  | 1012 | void | 
|  | 1013 | regex_traits<_CharT>::__init() | 
|  | 1014 | { | 
|  | 1015 | __ct_ = &use_facet<ctype<char_type> >(__loc_); | 
|  | 1016 | __col_ = &use_facet<collate<char_type> >(__loc_); | 
|  | 1017 | } | 
|  | 1018 |  | 
|  | 1019 | template <class _CharT> | 
|  | 1020 | typename regex_traits<_CharT>::locale_type | 
|  | 1021 | regex_traits<_CharT>::imbue(locale_type __l) | 
|  | 1022 | { | 
|  | 1023 | locale __r = __loc_; | 
|  | 1024 | __loc_ = __l; | 
|  | 1025 | __init(); | 
|  | 1026 | return __r; | 
|  | 1027 | } | 
|  | 1028 |  | 
|  | 1029 | // transform_primary is very FreeBSD-specific | 
|  | 1030 |  | 
|  | 1031 | template <class _CharT> | 
|  | 1032 | template <class _ForwardIterator> | 
|  | 1033 | typename regex_traits<_CharT>::string_type | 
|  | 1034 | regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, | 
|  | 1035 | _ForwardIterator __l, char) const | 
|  | 1036 | { | 
|  | 1037 | const string_type __s(__f, __l); | 
|  | 1038 | string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); | 
|  | 1039 | switch (__d.size()) | 
|  | 1040 | { | 
|  | 1041 | case 1: | 
|  | 1042 | break; | 
|  | 1043 | case 12: | 
|  | 1044 | __d[11] = __d[3]; | 
|  | 1045 | break; | 
|  | 1046 | default: | 
|  | 1047 | __d.clear(); | 
|  | 1048 | break; | 
|  | 1049 | } | 
|  | 1050 | return __d; | 
|  | 1051 | } | 
|  | 1052 |  | 
|  | 1053 | template <class _CharT> | 
|  | 1054 | template <class _ForwardIterator> | 
|  | 1055 | typename regex_traits<_CharT>::string_type | 
|  | 1056 | regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, | 
|  | 1057 | _ForwardIterator __l, wchar_t) const | 
|  | 1058 | { | 
|  | 1059 | const string_type __s(__f, __l); | 
|  | 1060 | string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); | 
|  | 1061 | switch (__d.size()) | 
|  | 1062 | { | 
|  | 1063 | case 1: | 
|  | 1064 | break; | 
|  | 1065 | case 3: | 
|  | 1066 | __d[2] = __d[0]; | 
|  | 1067 | break; | 
|  | 1068 | default: | 
|  | 1069 | __d.clear(); | 
|  | 1070 | break; | 
|  | 1071 | } | 
|  | 1072 | return __d; | 
|  | 1073 | } | 
|  | 1074 |  | 
|  | 1075 | // lookup_collatename is very FreeBSD-specific | 
|  | 1076 |  | 
| Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame^] | 1077 | string __get_collation_name(const char* __s); | 
| Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1078 |  | 
|  | 1079 | template <class _CharT> | 
|  | 1080 | template <class _ForwardIterator> | 
|  | 1081 | typename regex_traits<_CharT>::string_type | 
|  | 1082 | regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, | 
|  | 1083 | _ForwardIterator __l, char) const | 
|  | 1084 | { | 
|  | 1085 | string_type __s(__f, __l); | 
|  | 1086 | string_type __r; | 
|  | 1087 | if (!__s.empty()) | 
|  | 1088 | { | 
|  | 1089 | __r = __get_collation_name(__s.c_str()); | 
|  | 1090 | if (__r.empty() && __s.size() <= 2) | 
|  | 1091 | { | 
|  | 1092 | __r = __col_->transform(__s.data(), __s.data() + __s.size()); | 
|  | 1093 | if (__r.size() == 1 || __r.size() == 12) | 
|  | 1094 | __r = __s; | 
|  | 1095 | else | 
|  | 1096 | __r.clear(); | 
|  | 1097 | } | 
|  | 1098 | } | 
|  | 1099 | return __r; | 
|  | 1100 | } | 
|  | 1101 |  | 
|  | 1102 | template <class _CharT> | 
|  | 1103 | template <class _ForwardIterator> | 
|  | 1104 | typename regex_traits<_CharT>::string_type | 
|  | 1105 | regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, | 
|  | 1106 | _ForwardIterator __l, wchar_t) const | 
|  | 1107 | { | 
|  | 1108 | string_type __s(__f, __l); | 
|  | 1109 | string __n; | 
|  | 1110 | __n.reserve(__s.size()); | 
|  | 1111 | for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); | 
|  | 1112 | __i != __e; ++__i) | 
|  | 1113 | { | 
|  | 1114 | if (static_cast<unsigned>(*__i) >= 127) | 
|  | 1115 | return string_type(); | 
|  | 1116 | __n.push_back(char(*__i)); | 
|  | 1117 | } | 
|  | 1118 | string_type __r; | 
|  | 1119 | if (!__s.empty()) | 
|  | 1120 | { | 
|  | 1121 | __n = __get_collation_name(__n.c_str()); | 
|  | 1122 | if (!__n.empty()) | 
|  | 1123 | __r.assign(__n.begin(), __n.end()); | 
|  | 1124 | else if (__s.size() <= 2) | 
|  | 1125 | { | 
|  | 1126 | __r = __col_->transform(__s.data(), __s.data() + __s.size()); | 
|  | 1127 | if (__r.size() == 1 || __r.size() == 3) | 
|  | 1128 | __r = __s; | 
|  | 1129 | else | 
|  | 1130 | __r.clear(); | 
|  | 1131 | } | 
|  | 1132 | } | 
|  | 1133 | return __r; | 
|  | 1134 | } | 
|  | 1135 |  | 
| Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame^] | 1136 | // lookup_classname | 
|  | 1137 |  | 
|  | 1138 | ctype_base::mask __get_classname(const char* __s, bool __icase); | 
|  | 1139 |  | 
|  | 1140 | template <class _CharT> | 
|  | 1141 | template <class _ForwardIterator> | 
|  | 1142 | typename regex_traits<_CharT>::char_class_type | 
|  | 1143 | regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, | 
|  | 1144 | _ForwardIterator __l, | 
|  | 1145 | bool __icase, char) const | 
|  | 1146 | { | 
|  | 1147 | string_type __s(__f, __l); | 
|  | 1148 | __ct_->tolower(&__s[0], &__s[0] + __s.size()); | 
|  | 1149 | return __get_classname(__s.c_str(), __icase); | 
|  | 1150 | } | 
|  | 1151 |  | 
|  | 1152 | template <class _CharT> | 
|  | 1153 | template <class _ForwardIterator> | 
|  | 1154 | typename regex_traits<_CharT>::char_class_type | 
|  | 1155 | regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, | 
|  | 1156 | _ForwardIterator __l, | 
|  | 1157 | bool __icase, wchar_t) const | 
|  | 1158 | { | 
|  | 1159 | string_type __s(__f, __l); | 
|  | 1160 | __ct_->tolower(&__s[0], &__s[0] + __s.size()); | 
|  | 1161 | string __n; | 
|  | 1162 | __n.reserve(__s.size()); | 
|  | 1163 | for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); | 
|  | 1164 | __i != __e; ++__i) | 
|  | 1165 | { | 
|  | 1166 | if (static_cast<unsigned>(*__i) >= 127) | 
|  | 1167 | return char_class_type(); | 
|  | 1168 | __n.push_back(char(*__i)); | 
|  | 1169 | } | 
|  | 1170 | return __get_classname(__n.c_str(), __icase); | 
|  | 1171 | } | 
|  | 1172 |  | 
|  | 1173 | template <class _CharT> | 
|  | 1174 | bool | 
|  | 1175 | regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const | 
|  | 1176 | { | 
|  | 1177 | if (__ct_->is(__m, __c)) | 
|  | 1178 | return true; | 
|  | 1179 | return (__c == '_' && (__m & __regex_word)); | 
|  | 1180 | } | 
|  | 1181 |  | 
|  | 1182 | template <class _CharT> | 
|  | 1183 | int | 
|  | 1184 | regex_traits<_CharT>::__value(unsigned char __ch, int __radix) | 
|  | 1185 | { | 
|  | 1186 | if ((__ch & 0xF8u) == 0x30)  // '0' <= __ch && __ch <= '7' | 
|  | 1187 | return __ch - '0'; | 
|  | 1188 | if (__radix != 8) | 
|  | 1189 | { | 
|  | 1190 | if ((__ch & 0xFEu) == 0x38)  // '8' <= __ch && __ch <= '9' | 
|  | 1191 | return __ch - '0'; | 
|  | 1192 | if (__radix == 16) | 
|  | 1193 | { | 
|  | 1194 | __ch |= 0x20;  // tolower | 
|  | 1195 | if ('a' <= __ch && __ch <= 'f') | 
|  | 1196 | return __ch - 'a' + 10; | 
|  | 1197 | } | 
|  | 1198 | } | 
|  | 1199 | return -1; | 
|  | 1200 | } | 
|  | 1201 |  | 
|  | 1202 | template <class _CharT> | 
|  | 1203 | inline | 
|  | 1204 | int | 
|  | 1205 | regex_traits<_CharT>::__value(wchar_t __ch, int __radix) const | 
|  | 1206 | { | 
|  | 1207 | return __value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix); | 
|  | 1208 | } | 
|  | 1209 |  | 
| Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1210 | _LIBCPP_END_NAMESPACE_STD | 
|  | 1211 |  | 
|  | 1212 | #endif  // _LIBCPP_REGEX |