Debian Codegraph @

headers/regex

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