1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571
|
/* Copyright (C) 2015 Povilas Kanapickas <povilas@radix.lt>
This file is part of cppreference-doc
This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
Unported License. To view a copy of this license, visit
http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative
Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
*/
#ifndef CPPREFERENCE_REGEX_H
#define CPPREFERENCE_REGEX_H
#if CPPREFERENCE_STDVER>= 2011
namespace std {
namespace regex_constants {
typedef int syntax_option_type; // actually unspecified
constexpr syntax_option_type icase;
constexpr syntax_option_type nosubs;
constexpr syntax_option_type optimize;
constexpr syntax_option_type collate;
constexpr syntax_option_type ECMAScript;
constexpr syntax_option_type basic;
constexpr syntax_option_type extended;
constexpr syntax_option_type awk;
constexpr syntax_option_type grep;
constexpr syntax_option_type egrep;
typedef int match_flag_type; // actually unspecified
constexpr match_flag_type match_default = 0;
constexpr match_flag_type match_not_bol;
constexpr match_flag_type match_not_eol;
constexpr match_flag_type match_not_bow;
constexpr match_flag_type match_not_eow;
constexpr match_flag_type match_any;
constexpr match_flag_type match_not_null;
constexpr match_flag_type match_continuous;
constexpr match_flag_type match_prev_avail;
constexpr match_flag_type format_default = 0;
constexpr match_flag_type format_sed;
constexpr match_flag_type format_no_copy;
constexpr match_flag_type format_first_only;
typedef int error_type; // actually unspecified
constexpr error_type error_collate;
constexpr error_type error_ctype;
constexpr error_type error_escape;
constexpr error_type error_backref;
constexpr error_type error_brack;
constexpr error_type error_paren;
constexpr error_type error_brace;
constexpr error_type error_badbrace;
constexpr error_type error_range;
constexpr error_type error_space;
constexpr error_type error_badrepeat;
constexpr error_type error_complexity;
constexpr error_type error_stack;
} // namespace regex_constants
template<class CharT>
class regex_traits {
public:
typedef CharT char_type;
typedef std::basic_string<CharT> string_type;
typedef void* locale_type; // not specified
typedef int char_class_type; // unspecified bitmask type
regex_traits();
static std::size_t length(const char_type* p);
CharT translate(CharT c) const;
CharT translate_nocase(CharT c) const;
template<class ForwardIt>
string_type transform(ForwardIt first, ForwardIt last) const;
template<class ForwardIt>
string_type transform_primary(ForwardIt first, ForwardIt last) const;
template<class ForwardIt>
string_type lookup_collatename(ForwardIt first, ForwardIt last) const;
template<class ForwardIt>
char_class_type lookup_classname(ForwardIt first,
ForwardIt last,
bool icase = false) const;
bool isctype(CharT c, char_class_type f) const;
int value(CharT ch, int radix) const;
locale_type imbue(locale_type loc);
locale_type getloc() const;
};
class regex_error : public std::runtime_error {
public:
explicit regex_error(std::regex_constants::error_type ecode);
std::regex_constants::error_type code() const;
};
template <
class CharT,
class Traits = std::regex_traits<CharT>
> class basic_regex {
public:
typedef CharT value_type;
typedef Traits traits_type;
typedef typename Traits::string_type string_type;
typedef typename Traits::locale_type locale_type;
typedef regex_constants::syntax_option_type flag_type;
basic_regex();
explicit basic_regex(const CharT* s,
flag_type f = std::regex_constants::ECMAScript);
basic_regex(const CharT* s, std::size_t count,
flag_type f = std::regex_constants::ECMAScript);
basic_regex(const basic_regex& other);
basic_regex(basic_regex&& other);
template<class ST, class SA>
explicit basic_regex(const std::basic_string<CharT, ST, SA>& str,
flag_type f = std::regex_constants::ECMAScript);
template<class ForwardIt>
basic_regex(ForwardIt first, ForwardIt last,
flag_type f = std::regex_constants::ECMAScript);
basic_regex(std::initializer_list<CharT> init,
flag_type f = std::regex_constants::ECMAScript);
~basic_regex();
basic_regex& operator=(const basic_regex& other);
basic_regex& operator=(basic_regex&& other);
basic_regex& operator=(const CharT* ptr);
basic_regex& operator=(std::initializer_list<CharT> il);
template<class ST, class SA>
basic_regex& operator=(const std::basic_string<CharT, ST, SA>& p);
basic_regex& assign(const basic_regex& other);
basic_regex& assign(basic_regex&& that);
basic_regex& assign(const CharT* s,
flag_type f = std::regex_constants::ECMAScript);
basic_regex& assign(const charT* ptr, size_t count,
flag_type f = std::regex_constants::ECMAScript);
template<class ST, class SA>
basic_regex& assign(const std::basic_string<CharT, ST, SA>& str,
flag_type f = std::regex_constants::ECMAScript);
template<class InputIt>
basic_regex& assign(InputIt first, InputIt last,
flag_type f = std::regex_constants::ECMAScript);
basic_regex& assign(std::initializer_list<CharT> ilist,
flag_type f = std::regex_constants::ECMAScript);
unsigned mark_count() const;
flag_type flags() const;
locale_type imbue(locale_type loc);
void swap(basic_regex& other);
};
typedef basic_regex<char> regex;
typedef basic_regex<wchar_t> wregex;
template<class BidirIt>
class sub_match : public pair<BidirIt, BidirIt> {
public:
typedef BidirIt iterator;
#if CPPREFERENCE_SIMPLIFY_TYPEDEFS
typedef BidirIt::value_type value_type;
typedef ptrdiff_t difference_type;
#else
typedef typename std::iterator_traits<BidirIt>::value_type value_type;
typedef typename std::iterator_traits<BidirIt>::difference_type difference_type;
#endif
bool matched;
constexpr sub_match();
difference_type length() const;
operator string_type() const;
string_type str() const;
int compare(const sub_match& m) const;
int compare(const string_type& s) const;
int compare(const value_type* c) const;
};
// SIMPLIFIED: comparison operators omitted
template<class CharT, class Traits, class BidirIt>
std::basic_ostream<CharT, Traits>&
operator<<(std::basic_ostream<CharT, Traits>& os,
const sub_match<BidirIt>& m);
typedef sub_match<const char*> csub_match;
typedef sub_match<const wchar_t*> wcsub_match;
typedef sub_match<std::string::const_iterator> ssub_match;
typedef sub_match<std::wstring::const_iterator> wssub_match;
template <
class BidirIt,
class Alloc = std::allocator<std::sub_match<BidirIt>>
> class match_results {
public:
typedef Allocator allocator_type;
typedef sub_match<BidirIt> value_type;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef value_type* const_iterator; // actually impl-defined
typedef const_iterator iterator;
typedef typename std::iterator_traits<BidirIt>::difference_type difference_type;
typedef typename std::allocator_traits<Alloc>::size_type size_type;
typedef typename std::iterator_traits<BidirIt>::value_type char_type;
typedef std::basic_string<char_type> string_type;
explicit match_results(const Allocator& a = Allocator());
match_results(const match_results& rhs);
match_results(match_results&& rhs);
~match_results();
match_results& operator=(const match_results& other);
match_results& operator=(match_results&& other);
allocator_type get_allocator() const;
bool ready() const;
bool empty() const;
size_type size() const;
size_type max_size() const;
difference_type length(size_type n = 0) const;
difference_type position(size_type sub = 0) const;
string_type str(size_type n = 0) const;
const_reference operator[](size_type n) const;
const_reference prefix() const;
const_reference suffix() const;
iterator begin();
const_iterator begin() const;
\
const_iterator cbegin() const;
iterator end();
const_iterator end() const;
\
const_iterator cend() const;
template<class OutputIt>
OutputIter format(OutputIt out,
const char_type* fmt_first, const char_type* fmt_last,
std::regex_constants::match_flag_type flags =
std::regex_constants::format_default) const;
template<class OutputIt, class ST, class SA>
OutputIter format(OutputIt out,
const basic_string<char_type, ST, SA>& fmt,
std::regex_constants::match_flag_type flags =
std::regex_constants::format_default) const;
template<class ST, class SA>
std::basic_string<char_type, ST, SA>
format(const std::basic_string<char_type, ST, SA>& fmt,
std::regex_constants::match_flag_type flags =
std::regex_constants::format_default) const;
string_type format(const char_type* fmt_s,
std::regex_constants::match_flag_type flags =
std::regex_constants::format_default) const;
void swap(match_results& other);
};
template<class BidirIt, class Alloc>
bool operator==(match_results<BidirIt, Alloc>& lhs,
match_results<BidirIt, Alloc>& rhs);
template<class BidirIt, class Alloc>
bool operator!=(match_results<BidirIt, Alloc>& lhs,
match_results<BidirIt, Alloc>& rhs);
template<class BidirIt, class Alloc>
void swap(match_results<BidirIt, Alloc>& x1,
match_results<BidirIt, Alloc>& x2);
typedef match_results<const char*> cmatch;
typedef match_results<const wchar_t*> wcmatch;
typedef match_results<std::string::const_iterator> smatch;
typedef match_results<std::wstring::const_iterator> wsmatch;
template <
class BidirIt,
class CharT = typename std::iterator_traits<BidirIt>::value_type,
class Traits = std::regex_traits<CharT>
> class regex_iterator {
public:
typedef match_result<BidirIt> value_type;
typedef ptrdiff_t difference_type;
typedef const value_type* pointer;
typedef const value_type& reference;
typedef forward_iterator_tag iterator_category;
typedef basic_regex<CharT, Traits> regex_type;
regex_iterator();
regex_iterator(BidirIt a, BidirIt b,
const regex_type& re,
std::regex_constants::match_flag_type m =
std::regex_constants::match_default);
regex_iterator(const regex_iterator& other);
#if CPPREFERENCE_STDVER>= 2014
regex_iterator(BidirIt, BidirIt,
regex_type&&,
std::regex_constants::match_flag_type =
std::regex_constants::match_default) = delete;
#endif
regex_iterator& operator=(const regex_iterator& other);
bool operator==(const regex_iterator& rhs) const;
bool operator!=(const regex_iterator& rhs) const;
const value_type& operator*() const;
const value_type* operator->() const;
regex_iterator& operator++();
regex_iterator operator++(int);
};
typedef regex_iterator<const char*> cregex_iterator;
typedef regex_iterator<const wchar_t*> wcregex_iterator;
typedef regex_iterator<std::string::const_iterator> sregex_iterator;
typedef regex_iterator<std::wstring::const_iterator> wsregex_iterator;
template <
class BidirIt,
class CharT = typename std::iterator_traits<BidirIt>::value_type,
class Traits = std::regex_traits<CharT>
> class regex_token_iterator {
public:
typedef sub_match<BidirIt> value_type;
typedef ptrdiff_t difference_type;
typedef const value_type* pointer;
typedef const value_type& reference;
typedef forward_iterator_tag iterator_category;
typedef basic_regex<CharT, Traits> regex_type;
regex_token_iterator();
regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
const regex_type& re,
int submatch = 0,
std::regex_constants::match_flag_type m =
std::regex_constants::match_default);
regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
const regex_type& re,
const std::vector<int>& submatches,
std::regex_constants::match_flag_type m =
std::regex_constants::match_default);
regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
const regex_type& re,
std::initializer_list<int> submatches,
std::regex_constants::match_flag_type m =
std::regex_constants::match_default);
template <std::size_t N>
regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
const regex_type& re,
const int (&submatches)[N],
std::regex_constants::match_flag_type m =
std::regex_constants::match_default);
regex_token_iterator(const regex_token_iterator& other);
#if CPPREFERENCE_STDVER>= 2014
regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
regex_type&& re,
int submatch = 0,
std::regex_constants::match_flag_type m =
std::regex_constants::match_default) = delete;
regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
regex_type&& re,
const std::vector<int>& submatches,
std::regex_constants::match_flag_type m =
std::regex_constants::match_default) = delete;
regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
regex_type&& re,
std::initializer_list<int> submatches,
std::regex_constants::match_flag_type m =
std::regex_constants::match_default) = delete;
template <std::size_t N>
regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
regex_type&& re,
const int (&submatches)[N],
std::regex_constants::match_flag_type m =
std::regex_constants::match_default) = delete;
#endif
regex_token_iterator& operator=(const regex_token_iterator& other);
bool operator==(const regex_token_iterator& rhs) const;
bool operator!=(const regex_token_iterator& rhs) const;
const value_type& operator*() const;
const value_type* operator->() const;
regex_iterator& operator++();
regex_iterator operator++(int);
};
typedef regex_token_iterator<const char*> cregex_token_iterator;
typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
typedef regex_token_iterator<std::string::const_iterator> sregex_token_iterator;
typedef regex_token_iterator<std::wstring::const_iterator> wsregex_token_iterator;
// algorithms
template<class BidirIt,
class Alloc, class CharT, class Traits>
bool regex_match(BidirIt first, BidirIt last,
std::match_results<BidirIt, Alloc>& m,
const std::basic_regex<CharT, Traits>& e,
std::regex_constants::match_flag_type flags =
std::regex_constants::match_default);
template<class BidirIt,
class CharT, class Traits>
bool regex_match(BidirIt first, BidirIt last,
const std::basic_regex<CharT, Traits>& e,
std::regex_constants::match_flag_type flags =
std::regex_constants::match_default);
template<class CharT, class Alloc, class Traits>
bool regex_match(const CharT* str,
std::match_results<const CharT*, Alloc>& m,
const std::basic_regex<CharT, Traits>& e,
std::regex_constants::match_flag_type flags =
std::regex_constants::match_default);
template<class STraits, class SAlloc,
class Alloc, class CharT, class Traits>
bool regex_match(const std::basic_string<CharT, STraits, SAlloc>& s,
std::match_results<typename std::basic_string<CharT, STraits, SAlloc>::const_iterator, Alloc>& m,
const std::basic_regex<CharT, Traits>& e,
std::regex_constants::match_flag_type flags =
std::regex_constants::match_default);
template<class CharT, class Traits>
bool regex_match(const CharT* str,
const std::basic_regex<CharT, Traits>& e,
std::regex_constants::match_flag_type flags =
std::regex_constants::match_default);
template<class STraits, class SAlloc,
class CharT, class Traits>
bool regex_match(const std::basic_string<CharT, STraits, SAlloc>& s,
const std::basic_regex<CharT, Traits>& e,
std::regex_constants::match_flag_type flags =
std::regex_constants::match_default);
template<class BidirIt,
class Alloc, class CharT, class Traits>
bool regex_search(BidirIt first, BidirIt last,
std::match_results<BidirIt, Alloc>& m,
const std::basic_regex<CharT, Traits>& e,
std::regex_constants::match_flag_type flags =
std::regex_constants::match_default);
template<class Alloc, class CharT, class Traits>
bool regex_search(const CharT* str,
std::match_results<BidirIt, Alloc>& m,
const std::basic_regex<CharT, Traits>& e,
std::regex_constants::match_flag_type flags =
std::regex_constants::match_default);
template<class STraits, class SAlloc,
class Alloc, class CharT, class Traits>
bool regex_search(const std::basic_string<CharT, STraits, SAlloc>& s,
std::match_results<typename std::basic_string<CharT, STraits, SAlloc>::const_iterator, Alloc>& m,
const std::basic_regex<CharT, Traits>& e,
std::regex_constants::match_flag_type flags =
std::regex_constants::match_default);
template<class BidirIt,
class CharT, class Traits>
bool regex_search(BidirIt first, BidirIt last,
const std::basic_regex<CharT, Traits>& e,
std::regex_constants::match_flag_type flags =
std::regex_constants::match_default);
template<class CharT, class Traits>
bool regex_search(const CharT* str,
const std::basic_regex<CharT, Traits>& e,
std::regex_constants::match_flag_type flags =
std::regex_constants::match_default);
template<class STraits, class SAlloc,
class CharT, class Traits>
bool regex_search(const std::basic_string<CharT, STraits, SAlloc>& s,
const std::basic_regex<CharT, Traits>& e,
std::regex_constants::match_flag_type flags =
std::regex_constants::match_default);
template<class OutputIt, class BidirIt,
class Traits, class CharT,
class STraits, class SAlloc>
OutputIt regex_replace(OutputIt out, BidirIt first, BidirIt last,
const std::basic_regex<CharT, Traits>& re,
const std::basic_string<CharT, STraits, SAlloc>& fmt,
std::regex_constants::match_flag_type flags =
std::regex_constants::match_default);
template<class OutputIt, class BidirIt,
class Traits, class CharT>
OutputIt regex_replace(OutputIt out, BidirIt first, BidirIt last,
const std::basic_regex<CharT, Traits>& re,
const CharT* fmt,
std::regex_constants::match_flag_type flags =
std::regex_constants::match_default);
template<class Traits, class CharT,
class STraits, class SAlloc,
class FTraits, class FAlloc>
std::basic_string<CharT, STraits, SAlloc>
regex_replace(const std::basic_string<CharT, STraits, SAlloc>& s,
const std::basic_regex<CharT, Traits>& re,
const std::basic_string<CharT, FTraits, FAlloc>& fmt,
std::regex_constants::match_flag_type flags =
std::regex_constants::match_default);
template<class Traits, class CharT,
class STraits, class SAlloc>
std::basic_string<CharT, STraits, SAlloc>
regex_replace(const std::basic_string<CharT, STraits, SAlloc>& s,
const std::basic_regex<CharT, Traits>& re,
const CharT* fmt,
std::regex_constants::match_flag_type flags =
std::regex_constants::match_default);
template<class Traits, class CharT,
class STraits, class SAlloc>
std::basic_string<CharT>
regex_replace(const CharT* s,
const std::basic_regex<CharT, Traits>& re,
const std::basic_string<CharT, STraits, SAlloc>& fmt,
std::regex_constants::match_flag_type flags =
std::regex_constants::match_default);
template<class Traits, class CharT>
std::basic_string<CharT>
regex_replace(const CharT* s,
const std::basic_regex<CharT, Traits>& re,
const CharT* fmt,
std::regex_constants::match_flag_type flags =
std::regex_constants::match_default);
} // namespace std
#endif // CPPREFERENCE_STDVER>= 2011
#endif // CPPREFERENCE_REGEX_H
|