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 | namespace std _GLIBCXX_VISIBILITY(default) |
32 | { |
33 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
34 | _GLIBCXX_BEGIN_NAMESPACE_CXX11 |
35 | template<typename, typename> |
36 | class basic_regex; |
37 | |
38 | template<typename, typename> |
39 | class match_results; |
40 | |
41 | _GLIBCXX_END_NAMESPACE_CXX11 |
42 | _GLIBCXX_END_NAMESPACE_VERSION |
43 | |
44 | namespace __detail |
45 | { |
46 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
47 | |
48 | enum class _RegexExecutorPolicy : int |
49 | { _S_auto, _S_alternate }; |
50 | |
51 | template<typename _BiIter, typename _Alloc, |
52 | typename _CharT, typename _TraitsT, |
53 | _RegexExecutorPolicy __policy, |
54 | bool __match_mode> |
55 | bool |
56 | __regex_algo_impl(_BiIter __s, |
57 | _BiIter __e, |
58 | match_results<_BiIter, _Alloc>& __m, |
59 | const basic_regex<_CharT, _TraitsT>& __re, |
60 | regex_constants::match_flag_type __flags); |
61 | |
62 | template<typename, typename, typename, bool> |
63 | class _Executor; |
64 | |
65 | _GLIBCXX_END_NAMESPACE_VERSION |
66 | } |
67 | |
68 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
69 | _GLIBCXX_BEGIN_NAMESPACE_CXX11 |
70 | |
71 | |
72 | |
73 | |
74 | |
75 | |
76 | |
77 | |
78 | |
79 | |
80 | |
81 | |
82 | |
83 | |
84 | |
85 | |
86 | template<typename _Ch_type> |
87 | struct regex_traits |
88 | { |
89 | public: |
90 | typedef _Ch_type char_type; |
91 | typedef std::basic_string<char_type> string_type; |
92 | typedef std::locale locale_type; |
93 | private: |
94 | struct _RegexMask |
95 | { |
96 | typedef std::ctype_base::mask _BaseType; |
97 | _BaseType _M_base; |
98 | unsigned char _M_extended; |
99 | static constexpr unsigned char _S_under = 1 << 0; |
100 | static constexpr unsigned char _S_valid_mask = 0x1; |
101 | |
102 | constexpr _RegexMask(_BaseType __base = 0, |
103 | unsigned char __extended = 0) |
104 | : _M_base(__base), _M_extended(__extended) |
105 | { } |
106 | |
107 | constexpr _RegexMask |
108 | operator&(_RegexMask __other) const |
109 | { |
110 | return _RegexMask(_M_base & __other._M_base, |
111 | _M_extended & __other._M_extended); |
112 | } |
113 | |
114 | constexpr _RegexMask |
115 | operator|(_RegexMask __other) const |
116 | { |
117 | return _RegexMask(_M_base | __other._M_base, |
118 | _M_extended | __other._M_extended); |
119 | } |
120 | |
121 | constexpr _RegexMask |
122 | operator^(_RegexMask __other) const |
123 | { |
124 | return _RegexMask(_M_base ^ __other._M_base, |
125 | _M_extended ^ __other._M_extended); |
126 | } |
127 | |
128 | constexpr _RegexMask |
129 | operator~() const |
130 | { return _RegexMask(~_M_base, ~_M_extended); } |
131 | |
132 | _RegexMask& |
133 | operator&=(_RegexMask __other) |
134 | { return *this = (*this) & __other; } |
135 | |
136 | _RegexMask& |
137 | operator|=(_RegexMask __other) |
138 | { return *this = (*this) | __other; } |
139 | |
140 | _RegexMask& |
141 | operator^=(_RegexMask __other) |
142 | { return *this = (*this) ^ __other; } |
143 | |
144 | constexpr bool |
145 | operator==(_RegexMask __other) const |
146 | { |
147 | return (_M_extended & _S_valid_mask) |
148 | == (__other._M_extended & _S_valid_mask) |
149 | && _M_base == __other._M_base; |
150 | } |
151 | |
152 | constexpr bool |
153 | operator!=(_RegexMask __other) const |
154 | { return !((*this) == __other); } |
155 | |
156 | }; |
157 | public: |
158 | typedef _RegexMask char_class_type; |
159 | |
160 | public: |
161 | |
162 | |
163 | |
164 | regex_traits() { } |
165 | |
166 | |
167 | |
168 | |
169 | |
170 | |
171 | |
172 | |
173 | |
174 | |
175 | |
176 | static std::size_t |
177 | length(const char_type* __p) |
178 | { return string_type::traits_type::length(__p); } |
179 | |
180 | |
181 | |
182 | |
183 | |
184 | |
185 | |
186 | |
187 | char_type |
188 | translate(char_type __c) const |
189 | { return __c; } |
190 | |
191 | |
192 | |
193 | |
194 | |
195 | |
196 | |
197 | |
198 | |
199 | |
200 | char_type |
201 | translate_nocase(char_type __c) const |
202 | { |
203 | typedef std::ctype<char_type> __ctype_type; |
204 | const __ctype_type& __fctyp(use_facet<__ctype_type>(_M_locale)); |
205 | return __fctyp.tolower(__c); |
206 | } |
207 | |
208 | |
209 | |
210 | |
211 | |
212 | |
213 | |
214 | |
215 | |
216 | |
217 | |
218 | |
219 | |
220 | |
221 | |
222 | |
223 | |
224 | |
225 | |
226 | |
227 | |
228 | template<typename _Fwd_iter> |
229 | string_type |
230 | transform(_Fwd_iter __first, _Fwd_iter __last) const |
231 | { |
232 | typedef std::collate<char_type> __collate_type; |
233 | const __collate_type& __fclt(use_facet<__collate_type>(_M_locale)); |
234 | string_type __s(__first, __last); |
235 | return __fclt.transform(__s.data(), __s.data() + __s.size()); |
236 | } |
237 | |
238 | |
239 | |
240 | |
241 | |
242 | |
243 | |
244 | |
245 | |
246 | |
247 | |
248 | |
249 | |
250 | |
251 | |
252 | template<typename _Fwd_iter> |
253 | string_type |
254 | transform_primary(_Fwd_iter __first, _Fwd_iter __last) const |
255 | { |
256 | |
257 | |
258 | |
259 | |
260 | |
261 | |
262 | typedef std::ctype<char_type> __ctype_type; |
263 | const __ctype_type& __fctyp(use_facet<__ctype_type>(_M_locale)); |
264 | std::vector<char_type> __s(__first, __last); |
265 | __fctyp.tolower(__s.data(), __s.data() + __s.size()); |
266 | return this->transform(__s.data(), __s.data() + __s.size()); |
267 | } |
268 | |
269 | |
270 | |
271 | |
272 | |
273 | |
274 | |
275 | |
276 | |
277 | |
278 | |
279 | |
280 | template<typename _Fwd_iter> |
281 | string_type |
282 | lookup_collatename(_Fwd_iter __first, _Fwd_iter __last) const; |
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 | template<typename _Fwd_iter> |
322 | char_class_type |
323 | lookup_classname(_Fwd_iter __first, _Fwd_iter __last, |
324 | bool __icase = false) const; |
325 | |
326 | |
327 | |
328 | |
329 | |
330 | |
331 | |
332 | |
333 | |
334 | |
335 | |
336 | |
337 | |
338 | bool |
339 | isctype(_Ch_type __c, char_class_type __f) const; |
340 | |
341 | |
342 | |
343 | |
344 | |
345 | |
346 | |
347 | |
348 | |
349 | |
350 | |
351 | int |
352 | value(_Ch_type __ch, int __radix) const; |
353 | |
354 | |
355 | |
356 | |
357 | |
358 | |
359 | |
360 | |
361 | |
362 | |
363 | |
364 | |
365 | locale_type |
366 | imbue(locale_type __loc) |
367 | { |
368 | std::swap(_M_locale, __loc); |
369 | return __loc; |
370 | } |
371 | |
372 | |
373 | |
374 | |
375 | |
376 | locale_type |
377 | getloc() const |
378 | { return _M_locale; } |
379 | |
380 | protected: |
381 | locale_type _M_locale; |
382 | }; |
383 | |
384 | |
385 | |
386 | |
387 | |
388 | |
389 | |
390 | |
391 | |
392 | template<typename _Ch_type, typename _Rx_traits = regex_traits<_Ch_type>> |
393 | class basic_regex |
394 | { |
395 | public: |
396 | static_assert(is_same<_Ch_type, typename _Rx_traits::char_type>::value, |
397 | "regex traits class must have the same char_type"); |
398 | |
399 | |
400 | typedef _Ch_type value_type; |
401 | typedef _Rx_traits traits_type; |
402 | typedef typename traits_type::string_type string_type; |
403 | typedef regex_constants::syntax_option_type flag_type; |
404 | typedef typename traits_type::locale_type locale_type; |
405 | |
406 | |
407 | |
408 | |
409 | |
410 | |
411 | static constexpr flag_type icase = regex_constants::icase; |
412 | static constexpr flag_type nosubs = regex_constants::nosubs; |
413 | static constexpr flag_type optimize = regex_constants::optimize; |
414 | static constexpr flag_type collate = regex_constants::collate; |
415 | static constexpr flag_type ECMAScript = regex_constants::ECMAScript; |
416 | static constexpr flag_type basic = regex_constants::basic; |
417 | static constexpr flag_type extended = regex_constants::extended; |
418 | static constexpr flag_type awk = regex_constants::awk; |
419 | static constexpr flag_type grep = regex_constants::grep; |
420 | static constexpr flag_type egrep = regex_constants::egrep; |
421 | |
422 | |
423 | |
424 | |
425 | |
426 | |
427 | |
428 | basic_regex() |
429 | : _M_flags(ECMAScript), _M_loc(), _M_automaton(nullptr) |
430 | { } |
431 | |
432 | |
433 | |
434 | |
435 | |
436 | |
437 | |
438 | |
439 | |
440 | |
441 | |
442 | |
443 | explicit |
444 | basic_regex(const _Ch_type* __p, flag_type __f = ECMAScript) |
445 | : basic_regex(__p, __p + char_traits<_Ch_type>::length(__p), __f) |
446 | { } |
447 | |
448 | |
449 | |
450 | |
451 | |
452 | |
453 | |
454 | |
455 | |
456 | |
457 | |
458 | |
459 | |
460 | basic_regex(const _Ch_type* __p, std::size_t __len, |
461 | flag_type __f = ECMAScript) |
462 | : basic_regex(__p, __p + __len, __f) |
463 | { } |
464 | |
465 | |
466 | |
467 | |
468 | |
469 | |
470 | basic_regex(const basic_regex& __rhs) = default; |
471 | |
472 | |
473 | |
474 | |
475 | |
476 | |
477 | basic_regex(basic_regex&& __rhs) noexcept = default; |
478 | |
479 | |
480 | |
481 | |
482 | |
483 | |
484 | |
485 | |
486 | |
487 | |
488 | template<typename _Ch_traits, typename _Ch_alloc> |
489 | explicit |
490 | basic_regex(const std::basic_string<_Ch_type, _Ch_traits, |
491 | _Ch_alloc>& __s, |
492 | flag_type __f = ECMAScript) |
493 | : basic_regex(__s.data(), __s.data() + __s.size(), __f) |
494 | { } |
495 | |
496 | |
497 | |
498 | |
499 | |
500 | |
501 | |
502 | |
503 | |
504 | |
505 | |
506 | |
507 | |
508 | |
509 | template<typename _FwdIter> |
510 | basic_regex(_FwdIter __first, _FwdIter __last, |
511 | flag_type __f = ECMAScript) |
512 | : basic_regex(std::move(__first), std::move(__last), locale_type(), __f) |
513 | { } |
514 | |
515 | |
516 | |
517 | |
518 | |
519 | |
520 | |
521 | |
522 | |
523 | basic_regex(initializer_list<_Ch_type> __l, flag_type __f = ECMAScript) |
524 | : basic_regex(__l.begin(), __l.end(), __f) |
525 | { } |
526 | |
527 | |
528 | |
529 | |
530 | ~basic_regex() |
531 | { } |
532 | |
533 | |
534 | |
535 | |
536 | basic_regex& |
537 | operator=(const basic_regex& __rhs) |
538 | { return this->assign(__rhs); } |
539 | |
540 | |
541 | |
542 | |
543 | basic_regex& |
544 | operator=(basic_regex&& __rhs) noexcept |
545 | { return this->assign(std::move(__rhs)); } |
546 | |
547 | |
548 | |
549 | |
550 | |
551 | |
552 | |
553 | |
554 | basic_regex& |
555 | operator=(const _Ch_type* __p) |
556 | { return this->assign(__p); } |
557 | |
558 | |
559 | |
560 | |
561 | |
562 | |
563 | |
564 | |
565 | |
566 | basic_regex& |
567 | operator=(initializer_list<_Ch_type> __l) |
568 | { return this->assign(__l.begin(), __l.end()); } |
569 | |
570 | |
571 | |
572 | |
573 | |
574 | |
575 | |
576 | template<typename _Ch_traits, typename _Alloc> |
577 | basic_regex& |
578 | operator=(const basic_string<_Ch_type, _Ch_traits, _Alloc>& __s) |
579 | { return this->assign(__s); } |
580 | |
581 | |
582 | |
583 | |
584 | |
585 | |
586 | |
587 | basic_regex& |
588 | assign(const basic_regex& __rhs) |
589 | { |
590 | basic_regex __tmp(__rhs); |
591 | this->swap(__tmp); |
592 | return *this; |
593 | } |
594 | |
595 | |
596 | |
597 | |
598 | |
599 | |
600 | basic_regex& |
601 | assign(basic_regex&& __rhs) noexcept |
602 | { |
603 | basic_regex __tmp(std::move(__rhs)); |
604 | this->swap(__tmp); |
605 | return *this; |
606 | } |
607 | |
608 | |
609 | |
610 | |
611 | |
612 | |
613 | |
614 | |
615 | |
616 | |
617 | |
618 | |
619 | |
620 | |
621 | basic_regex& |
622 | assign(const _Ch_type* __p, flag_type __flags = ECMAScript) |
623 | { return this->assign(string_type(__p), __flags); } |
624 | |
625 | |
626 | |
627 | |
628 | |
629 | |
630 | |
631 | |
632 | |
633 | |
634 | |
635 | |
636 | |
637 | |
638 | basic_regex& |
639 | assign(const _Ch_type* __p, std::size_t __len, flag_type __flags) |
640 | { return this->assign(string_type(__p, __len), __flags); } |
641 | |
642 | |
643 | |
644 | |
645 | |
646 | |
647 | |
648 | |
649 | |
650 | |
651 | |
652 | |
653 | template<typename _Ch_traits, typename _Alloc> |
654 | basic_regex& |
655 | assign(const basic_string<_Ch_type, _Ch_traits, _Alloc>& __s, |
656 | flag_type __flags = ECMAScript) |
657 | { |
658 | return this->assign(basic_regex(__s.data(), __s.data() + __s.size(), |
659 | _M_loc, __flags)); |
660 | } |
661 | |
662 | |
663 | |
664 | |
665 | |
666 | |
667 | |
668 | |
669 | |
670 | |
671 | |
672 | |
673 | |
674 | |
675 | template<typename _InputIterator> |
676 | basic_regex& |
677 | assign(_InputIterator __first, _InputIterator __last, |
678 | flag_type __flags = ECMAScript) |
679 | { return this->assign(string_type(__first, __last), __flags); } |
680 | |
681 | |
682 | |
683 | |
684 | |
685 | |
686 | |
687 | |
688 | |
689 | |
690 | |
691 | |
692 | basic_regex& |
693 | assign(initializer_list<_Ch_type> __l, flag_type __flags = ECMAScript) |
694 | { return this->assign(__l.begin(), __l.end(), __flags); } |
695 | |
696 | |
697 | |
698 | |
699 | |
700 | |
701 | unsigned int |
702 | mark_count() const |
703 | { |
704 | if (_M_automaton) |
705 | return _M_automaton->_M_sub_count() - 1; |
706 | return 0; |
707 | } |
708 | |
709 | |
710 | |
711 | |
712 | |
713 | flag_type |
714 | flags() const |
715 | { return _M_flags; } |
716 | |
717 | |
718 | |
719 | |
720 | |
721 | |
722 | |
723 | locale_type |
724 | imbue(locale_type __loc) |
725 | { |
726 | std::swap(__loc, _M_loc); |
727 | _M_automaton.reset(); |
728 | return __loc; |
729 | } |
730 | |
731 | |
732 | |
733 | |
734 | |
735 | locale_type |
736 | getloc() const |
737 | { return _M_loc; } |
738 | |
739 | |
740 | |
741 | |
742 | |
743 | |
744 | |
745 | void |
746 | swap(basic_regex& __rhs) |
747 | { |
748 | std::swap(_M_flags, __rhs._M_flags); |
749 | std::swap(_M_loc, __rhs._M_loc); |
750 | std::swap(_M_automaton, __rhs._M_automaton); |
751 | } |
752 | |
753 | #ifdef _GLIBCXX_DEBUG |
754 | void |
755 | _M_dot(std::ostream& __ostr) |
756 | { _M_automaton->_M_dot(__ostr); } |
757 | #endif |
758 | |
759 | private: |
760 | typedef std::shared_ptr<const __detail::_NFA<_Rx_traits>> _AutomatonPtr; |
761 | |
762 | template<typename _FwdIter> |
763 | basic_regex(_FwdIter __first, _FwdIter __last, locale_type __loc, |
764 | flag_type __f) |
765 | : _M_flags(__f), _M_loc(std::move(__loc)), |
766 | _M_automaton(__detail::__compile_nfa<_FwdIter, _Rx_traits>( |
767 | std::move(__first), std::move(__last), _M_loc, _M_flags)) |
768 | { } |
769 | |
770 | template<typename _Bp, typename _Ap, typename _Cp, typename _Rp, |
771 | __detail::_RegexExecutorPolicy, bool> |
772 | friend bool __detail:: |
773 | #if _GLIBCXX_INLINE_VERSION |
774 | __7:: |
775 | #endif |
776 | __regex_algo_impl(_Bp, _Bp, match_results<_Bp, _Ap>&, |
777 | const basic_regex<_Cp, _Rp>&, |
778 | regex_constants::match_flag_type); |
779 | |
780 | template<typename, typename, typename, bool> |
781 | friend class __detail::_Executor; |
782 | |
783 | flag_type _M_flags; |
784 | locale_type _M_loc; |
785 | _AutomatonPtr _M_automaton; |
786 | }; |
787 | |
788 | #if __cplusplus < 201703L |
789 | template<typename _Ch, typename _Tr> |
790 | constexpr regex_constants::syntax_option_type |
791 | basic_regex<_Ch, _Tr>::icase; |
792 | |
793 | template<typename _Ch, typename _Tr> |
794 | constexpr regex_constants::syntax_option_type |
795 | basic_regex<_Ch, _Tr>::nosubs; |
796 | |
797 | template<typename _Ch, typename _Tr> |
798 | constexpr regex_constants::syntax_option_type |
799 | basic_regex<_Ch, _Tr>::optimize; |
800 | |
801 | template<typename _Ch, typename _Tr> |
802 | constexpr regex_constants::syntax_option_type |
803 | basic_regex<_Ch, _Tr>::collate; |
804 | |
805 | template<typename _Ch, typename _Tr> |
806 | constexpr regex_constants::syntax_option_type |
807 | basic_regex<_Ch, _Tr>::ECMAScript; |
808 | |
809 | template<typename _Ch, typename _Tr> |
810 | constexpr regex_constants::syntax_option_type |
811 | basic_regex<_Ch, _Tr>::basic; |
812 | |
813 | template<typename _Ch, typename _Tr> |
814 | constexpr regex_constants::syntax_option_type |
815 | basic_regex<_Ch, _Tr>::extended; |
816 | |
817 | template<typename _Ch, typename _Tr> |
818 | constexpr regex_constants::syntax_option_type |
819 | basic_regex<_Ch, _Tr>::awk; |
820 | |
821 | template<typename _Ch, typename _Tr> |
822 | constexpr regex_constants::syntax_option_type |
823 | basic_regex<_Ch, _Tr>::grep; |
824 | |
825 | template<typename _Ch, typename _Tr> |
826 | constexpr regex_constants::syntax_option_type |
827 | basic_regex<_Ch, _Tr>::egrep; |
828 | #endif |
829 | |
830 | |
831 | typedef basic_regex<char> regex; |
832 | |
833 | #ifdef _GLIBCXX_USE_WCHAR_T |
834 | |
835 | typedef basic_regex<wchar_t> wregex; |
836 | #endif |
837 | |
838 | |
839 | |
840 | |
841 | |
842 | |
843 | |
844 | |
845 | template<typename _Ch_type, typename _Rx_traits> |
846 | inline void |
847 | swap(basic_regex<_Ch_type, _Rx_traits>& __lhs, |
848 | basic_regex<_Ch_type, _Rx_traits>& __rhs) |
849 | { __lhs.swap(__rhs); } |
850 | |
851 | |
852 | |
853 | |
854 | |
855 | |
856 | |
857 | |
858 | |
859 | |
860 | |
861 | |
862 | |
863 | |
864 | |
865 | template<typename _BiIter> |
866 | class sub_match : public std::pair<_BiIter, _BiIter> |
867 | { |
868 | typedef iterator_traits<_BiIter> __iter_traits; |
869 | |
870 | public: |
871 | typedef typename __iter_traits::value_type value_type; |
872 | typedef typename __iter_traits::difference_type difference_type; |
873 | typedef _BiIter iterator; |
874 | typedef std::basic_string<value_type> string_type; |
875 | |
876 | bool matched; |
877 | |
878 | constexpr sub_match() : matched() { } |
879 | |
880 | |
881 | |
882 | |
883 | difference_type |
884 | length() const |
885 | { return this->matched ? std::distance(this->first, this->second) : 0; } |
886 | |
887 | |
888 | |
889 | |
890 | |
891 | |
892 | |
893 | |
894 | |
895 | |
896 | |
897 | operator string_type() const |
898 | { |
899 | return this->matched |
900 | ? string_type(this->first, this->second) |
901 | : string_type(); |
902 | } |
903 | |
904 | |
905 | |
906 | |
907 | |
908 | |
909 | string_type |
910 | str() const |
911 | { |
912 | return this->matched |
913 | ? string_type(this->first, this->second) |
914 | : string_type(); |
915 | } |
916 | |
917 | |
918 | |
919 | |
920 | |
921 | |
922 | |
923 | |
924 | |
925 | |
926 | int |
927 | compare(const sub_match& __s) const |
928 | { return this->str().compare(__s.str()); } |
929 | |
930 | |
931 | |
932 | |
933 | |
934 | |
935 | |
936 | |
937 | |
938 | |
939 | int |
940 | compare(const string_type& __s) const |
941 | { return this->str().compare(__s); } |
942 | |
943 | |
944 | |
945 | |
946 | |
947 | |
948 | |
949 | |
950 | |
951 | |
952 | int |
953 | compare(const value_type* __s) const |
954 | { return this->str().compare(__s); } |
955 | }; |
956 | |
957 | |
958 | |
959 | typedef sub_match<const char*> csub_match; |
960 | |
961 | |
962 | typedef sub_match<string::const_iterator> ssub_match; |
963 | |
964 | #ifdef _GLIBCXX_USE_WCHAR_T |
965 | |
966 | typedef sub_match<const wchar_t*> wcsub_match; |
967 | |
968 | |
969 | typedef sub_match<wstring::const_iterator> wssub_match; |
970 | #endif |
971 | |
972 | |
973 | |
974 | |
975 | |
976 | |
977 | |
978 | |
979 | |
980 | template<typename _BiIter> |
981 | inline bool |
982 | operator==(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs) |
983 | { return __lhs.compare(__rhs) == 0; } |
984 | |
985 | |
986 | |
987 | |
988 | |
989 | |
990 | |
991 | template<typename _BiIter> |
992 | inline bool |
993 | operator!=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs) |
994 | { return __lhs.compare(__rhs) != 0; } |
995 | |
996 | |
997 | |
998 | |
999 | |
1000 | |
1001 | |
1002 | template<typename _BiIter> |
1003 | inline bool |
1004 | operator<(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs) |
1005 | { return __lhs.compare(__rhs) < 0; } |
1006 | |
1007 | |
1008 | |
1009 | |
1010 | |
1011 | |
1012 | |
1013 | template<typename _BiIter> |
1014 | inline bool |
1015 | operator<=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs) |
1016 | { return __lhs.compare(__rhs) <= 0; } |
1017 | |
1018 | |
1019 | |
1020 | |
1021 | |
1022 | |
1023 | |
1024 | template<typename _BiIter> |
1025 | inline bool |
1026 | operator>=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs) |
1027 | { return __lhs.compare(__rhs) >= 0; } |
1028 | |
1029 | |
1030 | |
1031 | |
1032 | |
1033 | |
1034 | |
1035 | template<typename _BiIter> |
1036 | inline bool |
1037 | operator>(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs) |
1038 | { return __lhs.compare(__rhs) > 0; } |
1039 | |
1040 | |
1041 | template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc> |
1042 | using __sub_match_string = basic_string< |
1043 | typename iterator_traits<_Bi_iter>::value_type, |
1044 | _Ch_traits, _Ch_alloc>; |
1045 | |
1046 | |
1047 | |
1048 | |
1049 | |
1050 | |
1051 | |
1052 | |
1053 | template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc> |
1054 | inline bool |
1055 | operator==(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs, |
1056 | const sub_match<_Bi_iter>& __rhs) |
1057 | { |
1058 | typedef typename sub_match<_Bi_iter>::string_type string_type; |
1059 | return __rhs.compare(string_type(__lhs.data(), __lhs.size())) == 0; |
1060 | } |
1061 | |
1062 | |
1063 | |
1064 | |
1065 | |
1066 | |
1067 | |
1068 | |
1069 | template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc> |
1070 | inline bool |
1071 | operator!=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs, |
1072 | const sub_match<_Bi_iter>& __rhs) |
1073 | { return !(__lhs == __rhs); } |
1074 | |
1075 | |
1076 | |
1077 | |
1078 | |
1079 | |
1080 | |
1081 | template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc> |
1082 | inline bool |
1083 | operator<(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs, |
1084 | const sub_match<_Bi_iter>& __rhs) |
1085 | { |
1086 | typedef typename sub_match<_Bi_iter>::string_type string_type; |
1087 | return __rhs.compare(string_type(__lhs.data(), __lhs.size())) > 0; |
1088 | } |
1089 | |
1090 | |
1091 | |
1092 | |
1093 | |
1094 | |
1095 | |
1096 | template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc> |
1097 | inline bool |
1098 | operator>(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs, |
1099 | const sub_match<_Bi_iter>& __rhs) |
1100 | { return __rhs < __lhs; } |
1101 | |
1102 | |
1103 | |
1104 | |
1105 | |
1106 | |
1107 | |
1108 | template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc> |
1109 | inline bool |
1110 | operator>=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs, |
1111 | const sub_match<_Bi_iter>& __rhs) |
1112 | { return !(__lhs < __rhs); } |
1113 | |
1114 | |
1115 | |
1116 | |
1117 | |
1118 | |
1119 | |
1120 | template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc> |
1121 | inline bool |
1122 | operator<=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs, |
1123 | const sub_match<_Bi_iter>& __rhs) |
1124 | { return !(__rhs < __lhs); } |
1125 | |
1126 | |
1127 | |
1128 | |
1129 | |
1130 | |
1131 | |
1132 | |
1133 | template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc> |
1134 | inline bool |
1135 | operator==(const sub_match<_Bi_iter>& __lhs, |
1136 | const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs) |
1137 | { |
1138 | typedef typename sub_match<_Bi_iter>::string_type string_type; |
1139 | return __lhs.compare(string_type(__rhs.data(), __rhs.size())) == 0; |
1140 | } |
1141 | |
1142 | |
1143 | |
1144 | |
1145 | |
1146 | |
1147 | |
1148 | |
1149 | template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc> |
1150 | inline bool |
1151 | operator!=(const sub_match<_Bi_iter>& __lhs, |
1152 | const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs) |
1153 | { return !(__lhs == __rhs); } |
1154 | |
1155 | |
1156 | |
1157 | |
1158 | |
1159 | |
1160 | |
1161 | template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc> |
1162 | inline bool |
1163 | operator<(const sub_match<_Bi_iter>& __lhs, |
1164 | const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs) |
1165 | { |
1166 | typedef typename sub_match<_Bi_iter>::string_type string_type; |
1167 | return __lhs.compare(string_type(__rhs.data(), __rhs.size())) < 0; |
1168 | } |
1169 | |
1170 | |
1171 | |
1172 | |
1173 | |
1174 | |
1175 | |
1176 | template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc> |
1177 | inline bool |
1178 | operator>(const sub_match<_Bi_iter>& __lhs, |
1179 | const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs) |
1180 | { return __rhs < __lhs; } |
1181 | |
1182 | |
1183 | |
1184 | |
1185 | |
1186 | |
1187 | |
1188 | template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc> |
1189 | inline bool |
1190 | operator>=(const sub_match<_Bi_iter>& __lhs, |
1191 | const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs) |
1192 | { return !(__lhs < __rhs); } |
1193 | |
1194 | |
1195 | |
1196 | |
1197 | |
1198 | |
1199 | |
1200 | template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc> |
1201 | inline bool |
1202 | operator<=(const sub_match<_Bi_iter>& __lhs, |
1203 | const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs) |
1204 | { return !(__rhs < __lhs); } |
1205 | |
1206 | |
1207 | |
1208 | |
1209 | |
1210 | |
1211 | |
1212 | |
1213 | template<typename _Bi_iter> |
1214 | inline bool |
1215 | operator==(typename iterator_traits<_Bi_iter>::value_type const* __lhs, |
1216 | const sub_match<_Bi_iter>& __rhs) |
1217 | { return __rhs.compare(__lhs) == 0; } |
1218 | |
1219 | |
1220 | |
1221 | |
1222 | |
1223 | |
1224 | |
1225 | |
1226 | template<typename _Bi_iter> |
1227 | inline bool |
1228 | operator!=(typename iterator_traits<_Bi_iter>::value_type const* __lhs, |
1229 | const sub_match<_Bi_iter>& __rhs) |
1230 | { return !(__lhs == __rhs); } |
1231 | |
1232 | |
1233 | |
1234 | |
1235 | |
1236 | |
1237 | |
1238 | template<typename _Bi_iter> |
1239 | inline bool |
1240 | operator<(typename iterator_traits<_Bi_iter>::value_type const* __lhs, |
1241 | const sub_match<_Bi_iter>& __rhs) |
1242 | { return __rhs.compare(__lhs) > 0; } |
1243 | |
1244 | |
1245 | |
1246 | |
1247 | |
1248 | |
1249 | |
1250 | template<typename _Bi_iter> |
1251 | inline bool |
1252 | operator>(typename iterator_traits<_Bi_iter>::value_type const* __lhs, |
1253 | const sub_match<_Bi_iter>& __rhs) |
1254 | { return __rhs < __lhs; } |
1255 | |
1256 | |
1257 | |
1258 | |
1259 | |
1260 | |
1261 | |
1262 | template<typename _Bi_iter> |
1263 | inline bool |
1264 | operator>=(typename iterator_traits<_Bi_iter>::value_type const* __lhs, |
1265 | const sub_match<_Bi_iter>& __rhs) |
1266 | { return !(__lhs < __rhs); } |
1267 | |
1268 | |
1269 | |
1270 | |
1271 | |
1272 | |
1273 | |
1274 | template<typename _Bi_iter> |
1275 | inline bool |
1276 | operator<=(typename iterator_traits<_Bi_iter>::value_type const* __lhs, |
1277 | const sub_match<_Bi_iter>& __rhs) |
1278 | { return !(__rhs < __lhs); } |
1279 | |
1280 | |
1281 | |
1282 | |
1283 | |
1284 | |
1285 | |
1286 | |
1287 | template<typename _Bi_iter> |
1288 | inline bool |
1289 | operator==(const sub_match<_Bi_iter>& __lhs, |
1290 | typename iterator_traits<_Bi_iter>::value_type const* __rhs) |
1291 | { return __lhs.compare(__rhs) == 0; } |
1292 | |
1293 | |
1294 | |
1295 | |
1296 | |
1297 | |
1298 | |
1299 | |
1300 | template<typename _Bi_iter> |
1301 | inline bool |
1302 | operator!=(const sub_match<_Bi_iter>& __lhs, |
1303 | typename iterator_traits<_Bi_iter>::value_type const* __rhs) |
1304 | { return !(__lhs == __rhs); } |
1305 | |
1306 | |
1307 | |
1308 | |
1309 | |
1310 | |
1311 | |
1312 | template<typename _Bi_iter> |
1313 | inline bool |
1314 | operator<(const sub_match<_Bi_iter>& __lhs, |
1315 | typename iterator_traits<_Bi_iter>::value_type const* __rhs) |
1316 | { return __lhs.compare(__rhs) < 0; } |
1317 | |
1318 | |
1319 | |
1320 | |
1321 | |
1322 | |
1323 | |
1324 | template<typename _Bi_iter> |
1325 | inline bool |
1326 | operator>(const sub_match<_Bi_iter>& __lhs, |
1327 | typename iterator_traits<_Bi_iter>::value_type const* __rhs) |
1328 | { return __rhs < __lhs; } |
1329 | |
1330 | |
1331 | |
1332 | |
1333 | |
1334 | |
1335 | |
1336 | template<typename _Bi_iter> |
1337 | inline bool |
1338 | operator>=(const sub_match<_Bi_iter>& __lhs, |
1339 | typename iterator_traits<_Bi_iter>::value_type const* __rhs) |
1340 | { return !(__lhs < __rhs); } |
1341 | |
1342 | |
1343 | |
1344 | |
1345 | |
1346 | |
1347 | |
1348 | template<typename _Bi_iter> |
1349 | inline bool |
1350 | operator<=(const sub_match<_Bi_iter>& __lhs, |
1351 | typename iterator_traits<_Bi_iter>::value_type const* __rhs) |
1352 | { return !(__rhs < __lhs); } |
1353 | |
1354 | |
1355 | |
1356 | |
1357 | |
1358 | |
1359 | |
1360 | |
1361 | template<typename _Bi_iter> |
1362 | inline bool |
1363 | operator==(typename iterator_traits<_Bi_iter>::value_type const& __lhs, |
1364 | const sub_match<_Bi_iter>& __rhs) |
1365 | { |
1366 | typedef typename sub_match<_Bi_iter>::string_type string_type; |
1367 | return __rhs.compare(string_type(1, __lhs)) == 0; |
1368 | } |
1369 | |
1370 | |
1371 | |
1372 | |
1373 | |
1374 | |
1375 | |
1376 | |
1377 | template<typename _Bi_iter> |
1378 | inline bool |
1379 | operator!=(typename iterator_traits<_Bi_iter>::value_type const& __lhs, |
1380 | const sub_match<_Bi_iter>& __rhs) |
1381 | { return !(__lhs == __rhs); } |
1382 | |
1383 | |
1384 | |
1385 | |
1386 | |
1387 | |
1388 | |
1389 | template<typename _Bi_iter> |
1390 | inline bool |
1391 | operator<(typename iterator_traits<_Bi_iter>::value_type const& __lhs, |
1392 | const sub_match<_Bi_iter>& __rhs) |
1393 | { |
1394 | typedef typename sub_match<_Bi_iter>::string_type string_type; |
1395 | return __rhs.compare(string_type(1, __lhs)) > 0; |
1396 | } |
1397 | |
1398 | |
1399 | |
1400 | |
1401 | |
1402 | |
1403 | |
1404 | template<typename _Bi_iter> |
1405 | inline bool |
1406 | operator>(typename iterator_traits<_Bi_iter>::value_type const& __lhs, |
1407 | const sub_match<_Bi_iter>& __rhs) |
1408 | { return __rhs < __lhs; } |
1409 | |
1410 | |
1411 | |
1412 | |
1413 | |
1414 | |
1415 | |
1416 | template<typename _Bi_iter> |
1417 | inline bool |
1418 | operator>=(typename iterator_traits<_Bi_iter>::value_type const& __lhs, |
1419 | const sub_match<_Bi_iter>& __rhs) |
1420 | { return !(__lhs < __rhs); } |
1421 | |
1422 | |
1423 | |
1424 | |
1425 | |
1426 | |
1427 | |
1428 | template<typename _Bi_iter> |
1429 | inline bool |
1430 | operator<=(typename iterator_traits<_Bi_iter>::value_type const& __lhs, |
1431 | const sub_match<_Bi_iter>& __rhs) |
1432 | { return !(__rhs < __lhs); } |
1433 | |
1434 | |
1435 | |
1436 | |
1437 | |
1438 | |
1439 | |
1440 | |
1441 | template<typename _Bi_iter> |
1442 | inline bool |
1443 | operator==(const sub_match<_Bi_iter>& __lhs, |
1444 | typename iterator_traits<_Bi_iter>::value_type const& __rhs) |
1445 | { |
1446 | typedef typename sub_match<_Bi_iter>::string_type string_type; |
1447 | return __lhs.compare(string_type(1, __rhs)) == 0; |
1448 | } |
1449 | |
1450 | |
1451 | |
1452 | |
1453 | |
1454 | |
1455 | |
1456 | |
1457 | template<typename _Bi_iter> |
1458 | inline bool |
1459 | operator!=(const sub_match<_Bi_iter>& __lhs, |
1460 | typename iterator_traits<_Bi_iter>::value_type const& __rhs) |
1461 | { return !(__lhs == __rhs); } |
1462 | |
1463 | |
1464 | |
1465 | |
1466 | |
1467 | |
1468 | |
1469 | template<typename _Bi_iter> |
1470 | inline bool |
1471 | operator<(const sub_match<_Bi_iter>& __lhs, |
1472 | typename iterator_traits<_Bi_iter>::value_type const& __rhs) |
1473 | { |
1474 | typedef typename sub_match<_Bi_iter>::string_type string_type; |
1475 | return __lhs.compare(string_type(1, __rhs)) < 0; |
1476 | } |
1477 | |
1478 | |
1479 | |
1480 | |
1481 | |
1482 | |
1483 | |
1484 | template<typename _Bi_iter> |
1485 | inline bool |
1486 | operator>(const sub_match<_Bi_iter>& __lhs, |
1487 | typename iterator_traits<_Bi_iter>::value_type const& __rhs) |
1488 | { return __rhs < __lhs; } |
1489 | |
1490 | |
1491 | |
1492 | |
1493 | |
1494 | |
1495 | |
1496 | template<typename _Bi_iter> |
1497 | inline bool |
1498 | operator>=(const sub_match<_Bi_iter>& __lhs, |
1499 | typename iterator_traits<_Bi_iter>::value_type const& __rhs) |
1500 | { return !(__lhs < __rhs); } |
1501 | |
1502 | |
1503 | |
1504 | |
1505 | |
1506 | |
1507 | |
1508 | template<typename _Bi_iter> |
1509 | inline bool |
1510 | operator<=(const sub_match<_Bi_iter>& __lhs, |
1511 | typename iterator_traits<_Bi_iter>::value_type const& __rhs) |
1512 | { return !(__rhs < __lhs); } |
1513 | |
1514 | |
1515 | |
1516 | |
1517 | |
1518 | |
1519 | |
1520 | |
1521 | |
1522 | template<typename _Ch_type, typename _Ch_traits, typename _Bi_iter> |
1523 | inline |
1524 | basic_ostream<_Ch_type, _Ch_traits>& |
1525 | operator<<(basic_ostream<_Ch_type, _Ch_traits>& __os, |
1526 | const sub_match<_Bi_iter>& __m) |
1527 | { return __os << __m.str(); } |
1528 | |
1529 | |
1530 | |
1531 | |
1532 | |
1533 | |
1534 | |
1535 | |
1536 | |
1537 | |
1538 | |
1539 | |
1540 | |
1541 | |
1542 | |
1543 | |
1544 | |
1545 | |
1546 | |
1547 | |
1548 | |
1549 | |
1550 | |
1551 | |
1552 | |
1553 | template<typename _Bi_iter, |
1554 | typename _Alloc = allocator<sub_match<_Bi_iter> > > |
1555 | class match_results |
1556 | : private std::vector<sub_match<_Bi_iter>, _Alloc> |
1557 | { |
1558 | private: |
1559 | |
1560 | |
1561 | |
1562 | |
1563 | |
1564 | |
1565 | |
1566 | |
1567 | |
1568 | |
1569 | |
1570 | |
1571 | |
1572 | |
1573 | |
1574 | |
1575 | typedef std::vector<sub_match<_Bi_iter>, _Alloc> _Base_type; |
1576 | typedef std::iterator_traits<_Bi_iter> __iter_traits; |
1577 | typedef regex_constants::match_flag_type match_flag_type; |
1578 | |
1579 | public: |
1580 | |
1581 | |
1582 | |
1583 | |
1584 | typedef sub_match<_Bi_iter> value_type; |
1585 | typedef const value_type& const_reference; |
1586 | typedef const_reference reference; |
1587 | typedef typename _Base_type::const_iterator const_iterator; |
1588 | typedef const_iterator iterator; |
1589 | typedef typename __iter_traits::difference_type difference_type; |
1590 | typedef typename allocator_traits<_Alloc>::size_type size_type; |
1591 | typedef _Alloc allocator_type; |
1592 | typedef typename __iter_traits::value_type char_type; |
1593 | typedef std::basic_string<char_type> string_type; |
1594 | |
1595 | |
1596 | public: |
1597 | |
1598 | |
1599 | |
1600 | |
1601 | |
1602 | |
1603 | |
1604 | |
1605 | |
1606 | explicit |
1607 | match_results(const _Alloc& __a = _Alloc()) |
1608 | : _Base_type(__a) |
1609 | { } |
1610 | |
1611 | |
1612 | |
1613 | |
1614 | match_results(const match_results& __rhs) = default; |
1615 | |
1616 | |
1617 | |
1618 | |
1619 | match_results(match_results&& __rhs) noexcept = default; |
1620 | |
1621 | |
1622 | |
1623 | |
1624 | match_results& |
1625 | operator=(const match_results& __rhs) = default; |
1626 | |
1627 | |
1628 | |
1629 | |
1630 | match_results& |
1631 | operator=(match_results&& __rhs) = default; |
1632 | |
1633 | |
1634 | |
1635 | |
1636 | ~match_results() |
1637 | { } |
1638 | |
1639 | |
1640 | |
1641 | |
1642 | |
1643 | |
1644 | |
1645 | |
1646 | |
1647 | bool ready() const { return !_Base_type::empty(); } |
1648 | |
1649 | |
1650 | |
1651 | |
1652 | |
1653 | |
1654 | |
1655 | |
1656 | |
1657 | |
1658 | |
1659 | |
1660 | |
1661 | |
1662 | |
1663 | size_type |
1664 | size() const |
1665 | { return _Base_type::empty() ? 0 : _Base_type::size() - 3; } |
1666 | |
1667 | size_type |
1668 | max_size() const |
1669 | { return _Base_type::max_size(); } |
1670 | |
1671 | |
1672 | |
1673 | |
1674 | |
1675 | |
1676 | bool |
1677 | empty() const |
1678 | { return size() == 0; } |
1679 | |
1680 | |
1681 | |
1682 | |
1683 | |
1684 | |
1685 | |
1686 | |
1687 | |
1688 | |
1689 | |
1690 | |
1691 | |
1692 | |
1693 | |
1694 | |
1695 | difference_type |
1696 | length(size_type __sub = 0) const |
1697 | { return (*this)[__sub].length(); } |
1698 | |
1699 | |
1700 | |
1701 | |
1702 | |
1703 | |
1704 | |
1705 | |
1706 | |
1707 | |
1708 | |
1709 | |
1710 | difference_type |
1711 | position(size_type __sub = 0) const |
1712 | { return std::distance(_M_begin, (*this)[__sub].first); } |
1713 | |
1714 | |
1715 | |
1716 | |
1717 | |
1718 | |
1719 | |
1720 | |
1721 | |
1722 | |
1723 | string_type |
1724 | str(size_type __sub = 0) const |
1725 | { return string_type((*this)[__sub]); } |
1726 | |
1727 | |
1728 | |
1729 | |
1730 | |
1731 | |
1732 | |
1733 | |
1734 | |
1735 | |
1736 | |
1737 | |
1738 | const_reference |
1739 | operator[](size_type __sub) const |
1740 | { |
1741 | __glibcxx_assert( ready() ); |
1742 | return __sub < size() |
1743 | ? _Base_type::operator[](__sub) |
1744 | : _M_unmatched_sub(); |
1745 | } |
1746 | |
1747 | |
1748 | |
1749 | |
1750 | |
1751 | |
1752 | |
1753 | |
1754 | |
1755 | const_reference |
1756 | prefix() const |
1757 | { |
1758 | __glibcxx_assert( ready() ); |
1759 | return !empty() ? _M_prefix() : _M_unmatched_sub(); |
1760 | } |
1761 | |
1762 | |
1763 | |
1764 | |
1765 | |
1766 | |
1767 | |
1768 | |
1769 | |
1770 | const_reference |
1771 | suffix() const |
1772 | { |
1773 | __glibcxx_assert( ready() ); |
1774 | return !empty() ? _M_suffix() : _M_unmatched_sub(); |
1775 | } |
1776 | |
1777 | |
1778 | |
1779 | |
1780 | const_iterator |
1781 | begin() const |
1782 | { return _Base_type::begin(); } |
1783 | |
1784 | |
1785 | |
1786 | |
1787 | const_iterator |
1788 | cbegin() const |
1789 | { return this->begin(); } |
1790 | |
1791 | |
1792 | |
1793 | |
1794 | const_iterator |
1795 | end() const |
1796 | { return _Base_type::end() - (empty() ? 0 : 3); } |
1797 | |
1798 | |
1799 | |
1800 | |
1801 | const_iterator |
1802 | cend() const |
1803 | { return this->end(); } |
1804 | |
1805 | |
1806 | |
1807 | |
1808 | |
1809 | |
1810 | |
1811 | |
1812 | |
1813 | |
1814 | |
1815 | |
1816 | |
1817 | |
1818 | |
1819 | |
1820 | template<typename _Out_iter> |
1821 | _Out_iter |
1822 | format(_Out_iter __out, const char_type* __fmt_first, |
1823 | const char_type* __fmt_last, |
1824 | match_flag_type __flags = regex_constants::format_default) const; |
1825 | |
1826 | |
1827 | |
1828 | |
1829 | template<typename _Out_iter, typename _St, typename _Sa> |
1830 | _Out_iter |
1831 | format(_Out_iter __out, const basic_string<char_type, _St, _Sa>& __fmt, |
1832 | match_flag_type __flags = regex_constants::format_default) const |
1833 | { |
1834 | return format(__out, __fmt.data(), __fmt.data() + __fmt.size(), |
1835 | __flags); |
1836 | } |
1837 | |
1838 | |
1839 | |
1840 | |
1841 | template<typename _St, typename _Sa> |
1842 | basic_string<char_type, _St, _Sa> |
1843 | format(const basic_string<char_type, _St, _Sa>& __fmt, |
1844 | match_flag_type __flags = regex_constants::format_default) const |
1845 | { |
1846 | basic_string<char_type, _St, _Sa> __result; |
1847 | format(std::back_inserter(__result), __fmt, __flags); |
1848 | return __result; |
1849 | } |
1850 | |
1851 | |
1852 | |
1853 | |
1854 | string_type |
1855 | format(const char_type* __fmt, |
1856 | match_flag_type __flags = regex_constants::format_default) const |
1857 | { |
1858 | string_type __result; |
1859 | format(std::back_inserter(__result), |
1860 | __fmt, |
1861 | __fmt + char_traits<char_type>::length(__fmt), |
1862 | __flags); |
1863 | return __result; |
1864 | } |
1865 | |
1866 | |
1867 | |
1868 | |
1869 | |
1870 | |
1871 | |
1872 | |
1873 | |
1874 | |
1875 | |
1876 | allocator_type |
1877 | get_allocator() const |
1878 | { return _Base_type::get_allocator(); } |
1879 | |
1880 | |
1881 | |
1882 | |
1883 | |
1884 | |
1885 | |
1886 | |
1887 | |
1888 | |
1889 | |
1890 | void |
1891 | swap(match_results& __that) |
1892 | { |
1893 | using std::swap; |
1894 | _Base_type::swap(__that); |
1895 | swap(_M_begin, __that._M_begin); |
1896 | } |
1897 | |
1898 | |
1899 | private: |
1900 | template<typename, typename, typename, bool> |
1901 | friend class __detail::_Executor; |
1902 | |
1903 | template<typename, typename, typename> |
1904 | friend class regex_iterator; |
1905 | |
1906 | template<typename _Bp, typename _Ap, typename _Cp, typename _Rp, |
1907 | __detail::_RegexExecutorPolicy, bool> |
1908 | friend bool __detail:: |
1909 | #if _GLIBCXX_INLINE_VERSION |
1910 | __7:: |
1911 | #endif |
1912 | __regex_algo_impl(_Bp, _Bp, match_results<_Bp, _Ap>&, |
1913 | const basic_regex<_Cp, _Rp>&, |
1914 | regex_constants::match_flag_type); |
1915 | |
1916 | void |
1917 | _M_resize(unsigned int __size) |
1918 | { _Base_type::resize(__size + 3); } |
1919 | |
1920 | const_reference |
1921 | _M_unmatched_sub() const |
1922 | { return _Base_type::operator[](_Base_type::size() - 3); } |
1923 | |
1924 | sub_match<_Bi_iter>& |
1925 | _M_unmatched_sub() |
1926 | { return _Base_type::operator[](_Base_type::size() - 3); } |
1927 | |
1928 | const_reference |
1929 | _M_prefix() const |
1930 | { return _Base_type::operator[](_Base_type::size() - 2); } |
1931 | |
1932 | sub_match<_Bi_iter>& |
1933 | _M_prefix() |
1934 | { return _Base_type::operator[](_Base_type::size() - 2); } |
1935 | |
1936 | const_reference |
1937 | _M_suffix() const |
1938 | { return _Base_type::operator[](_Base_type::size() - 1); } |
1939 | |
1940 | sub_match<_Bi_iter>& |
1941 | _M_suffix() |
1942 | { return _Base_type::operator[](_Base_type::size() - 1); } |
1943 | |
1944 | _Bi_iter _M_begin; |
1945 | }; |
1946 | |
1947 | typedef match_results<const char*> cmatch; |
1948 | typedef match_results<string::const_iterator> smatch; |
1949 | #ifdef _GLIBCXX_USE_WCHAR_T |
1950 | typedef match_results<const wchar_t*> wcmatch; |
1951 | typedef match_results<wstring::const_iterator> wsmatch; |
1952 | #endif |
1953 | |
1954 | |
1955 | |
1956 | |
1957 | |
1958 | |
1959 | |
1960 | template<typename _Bi_iter, typename _Alloc> |
1961 | inline bool |
1962 | operator==(const match_results<_Bi_iter, _Alloc>& __m1, |
1963 | const match_results<_Bi_iter, _Alloc>& __m2) |
1964 | { |
1965 | if (__m1.ready() != __m2.ready()) |
1966 | return false; |
1967 | if (!__m1.ready()) |
1968 | return true; |
1969 | if (__m1.empty() != __m2.empty()) |
1970 | return false; |
1971 | if (__m1.empty()) |
1972 | return true; |
1973 | return __m1.prefix() == __m2.prefix() |
1974 | && __m1.size() == __m2.size() |
1975 | && std::equal(__m1.begin(), __m1.end(), __m2.begin()) |
1976 | && __m1.suffix() == __m2.suffix(); |
1977 | } |
1978 | |
1979 | |
1980 | |
1981 | |
1982 | |
1983 | |
1984 | template<typename _Bi_iter, class _Alloc> |
1985 | inline bool |
1986 | operator!=(const match_results<_Bi_iter, _Alloc>& __m1, |
1987 | const match_results<_Bi_iter, _Alloc>& __m2) |
1988 | { return !(__m1 == __m2); } |
1989 | |
1990 | |
1991 | |
1992 | |
1993 | |
1994 | |
1995 | |
1996 | |
1997 | |
1998 | template<typename _Bi_iter, typename _Alloc> |
1999 | inline void |
2000 | swap(match_results<_Bi_iter, _Alloc>& __lhs, |
2001 | match_results<_Bi_iter, _Alloc>& __rhs) |
2002 | { __lhs.swap(__rhs); } |
2003 | |
2004 | _GLIBCXX_END_NAMESPACE_CXX11 |
2005 | |
2006 | |
2007 | |
2008 | |
2009 | |
2010 | |
2011 | |
2012 | |
2013 | |
2014 | |
2015 | |
2016 | |
2017 | |
2018 | |
2019 | |
2020 | |
2021 | |
2022 | |
2023 | |
2024 | |
2025 | |
2026 | |
2027 | template<typename _Bi_iter, typename _Alloc, |
2028 | typename _Ch_type, typename _Rx_traits> |
2029 | inline bool |
2030 | regex_match(_Bi_iter __s, |
2031 | _Bi_iter __e, |
2032 | match_results<_Bi_iter, _Alloc>& __m, |
2033 | const basic_regex<_Ch_type, _Rx_traits>& __re, |
2034 | regex_constants::match_flag_type __flags |
2035 | = regex_constants::match_default) |
2036 | { |
2037 | return __detail::__regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, _Rx_traits, |
2038 | __detail::_RegexExecutorPolicy::_S_auto, true> |
2039 | (__s, __e, __m, __re, __flags); |
2040 | } |
2041 | |
2042 | |
2043 | |
2044 | |
2045 | |
2046 | |
2047 | |
2048 | |
2049 | |
2050 | |
2051 | |
2052 | |
2053 | |
2054 | |
2055 | |
2056 | template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits> |
2057 | inline bool |
2058 | regex_match(_Bi_iter __first, _Bi_iter __last, |
2059 | const basic_regex<_Ch_type, _Rx_traits>& __re, |
2060 | regex_constants::match_flag_type __flags |
2061 | = regex_constants::match_default) |
2062 | { |
2063 | match_results<_Bi_iter> __what; |
2064 | return regex_match(__first, __last, __what, __re, __flags); |
2065 | } |
2066 | |
2067 | |
2068 | |
2069 | |
2070 | |
2071 | |
2072 | |
2073 | |
2074 | |
2075 | |
2076 | |
2077 | |
2078 | |
2079 | |
2080 | |
2081 | template<typename _Ch_type, typename _Alloc, typename _Rx_traits> |
2082 | inline bool |
2083 | regex_match(const _Ch_type* __s, |
2084 | match_results<const _Ch_type*, _Alloc>& __m, |
2085 | const basic_regex<_Ch_type, _Rx_traits>& __re, |
2086 | regex_constants::match_flag_type __f |
2087 | = regex_constants::match_default) |
2088 | { return regex_match(__s, __s + _Rx_traits::length(__s), __m, __re, __f); } |
2089 | |
2090 | |
2091 | |
2092 | |
2093 | |
2094 | |
2095 | |
2096 | |
2097 | |
2098 | |
2099 | |
2100 | |
2101 | |
2102 | |
2103 | |
2104 | template<typename _Ch_traits, typename _Ch_alloc, |
2105 | typename _Alloc, typename _Ch_type, typename _Rx_traits> |
2106 | inline bool |
2107 | regex_match(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s, |
2108 | match_results<typename basic_string<_Ch_type, |
2109 | _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>& __m, |
2110 | const basic_regex<_Ch_type, _Rx_traits>& __re, |
2111 | regex_constants::match_flag_type __flags |
2112 | = regex_constants::match_default) |
2113 | { return regex_match(__s.begin(), __s.end(), __m, __re, __flags); } |
2114 | |
2115 | |
2116 | |
2117 | |
2118 | template<typename _Ch_traits, typename _Ch_alloc, |
2119 | typename _Alloc, typename _Ch_type, typename _Rx_traits> |
2120 | bool |
2121 | regex_match(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>&&, |
2122 | match_results<typename basic_string<_Ch_type, |
2123 | _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>&, |
2124 | const basic_regex<_Ch_type, _Rx_traits>&, |
2125 | regex_constants::match_flag_type |
2126 | = regex_constants::match_default) = delete; |
2127 | |
2128 | |
2129 | |
2130 | |
2131 | |
2132 | |
2133 | |
2134 | |
2135 | |
2136 | |
2137 | |
2138 | |
2139 | |
2140 | |
2141 | template<typename _Ch_type, class _Rx_traits> |
2142 | inline bool |
2143 | regex_match(const _Ch_type* __s, |
2144 | const basic_regex<_Ch_type, _Rx_traits>& __re, |
2145 | regex_constants::match_flag_type __f |
2146 | = regex_constants::match_default) |
2147 | { return regex_match(__s, __s + _Rx_traits::length(__s), __re, __f); } |
2148 | |
2149 | |
2150 | |
2151 | |
2152 | |
2153 | |
2154 | |
2155 | |
2156 | |
2157 | |
2158 | |
2159 | |
2160 | |
2161 | |
2162 | template<typename _Ch_traits, typename _Str_allocator, |
2163 | typename _Ch_type, typename _Rx_traits> |
2164 | inline bool |
2165 | regex_match(const basic_string<_Ch_type, _Ch_traits, _Str_allocator>& __s, |
2166 | const basic_regex<_Ch_type, _Rx_traits>& __re, |
2167 | regex_constants::match_flag_type __flags |
2168 | = regex_constants::match_default) |
2169 | { return regex_match(__s.begin(), __s.end(), __re, __flags); } |
2170 | |
2171 | |
2172 | |
2173 | |
2174 | |
2175 | |
2176 | |
2177 | |
2178 | |
2179 | |
2180 | |
2181 | |
2182 | |
2183 | |
2184 | |
2185 | template<typename _Bi_iter, typename _Alloc, |
2186 | typename _Ch_type, typename _Rx_traits> |
2187 | inline bool |
2188 | regex_search(_Bi_iter __s, _Bi_iter __e, |
2189 | match_results<_Bi_iter, _Alloc>& __m, |
2190 | const basic_regex<_Ch_type, _Rx_traits>& __re, |
2191 | regex_constants::match_flag_type __flags |
2192 | = regex_constants::match_default) |
2193 | { |
2194 | return __detail::__regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, _Rx_traits, |
2195 | __detail::_RegexExecutorPolicy::_S_auto, false> |
2196 | (__s, __e, __m, __re, __flags); |
2197 | } |
2198 | |
2199 | |
2200 | |
2201 | |
2202 | |
2203 | |
2204 | |
2205 | |
2206 | |
2207 | |
2208 | |
2209 | |
2210 | template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits> |
2211 | inline bool |
2212 | regex_search(_Bi_iter __first, _Bi_iter __last, |
2213 | const basic_regex<_Ch_type, _Rx_traits>& __re, |
2214 | regex_constants::match_flag_type __flags |
2215 | = regex_constants::match_default) |
2216 | { |
2217 | match_results<_Bi_iter> __what; |
2218 | return regex_search(__first, __last, __what, __re, __flags); |
2219 | } |
2220 | |
2221 | |
2222 | |
2223 | |
2224 | |
2225 | |
2226 | |
2227 | |
2228 | |
2229 | |
2230 | |
2231 | |
2232 | |
2233 | template<typename _Ch_type, class _Alloc, class _Rx_traits> |
2234 | inline bool |
2235 | regex_search(const _Ch_type* __s, |
2236 | match_results<const _Ch_type*, _Alloc>& __m, |
2237 | const basic_regex<_Ch_type, _Rx_traits>& __e, |
2238 | regex_constants::match_flag_type __f |
2239 | = regex_constants::match_default) |
2240 | { return regex_search(__s, __s + _Rx_traits::length(__s), __m, __e, __f); } |
2241 | |
2242 | |
2243 | |
2244 | |
2245 | |
2246 | |
2247 | |
2248 | |
2249 | |
2250 | |
2251 | |
2252 | template<typename _Ch_type, typename _Rx_traits> |
2253 | inline bool |
2254 | regex_search(const _Ch_type* __s, |
2255 | const basic_regex<_Ch_type, _Rx_traits>& __e, |
2256 | regex_constants::match_flag_type __f |
2257 | = regex_constants::match_default) |
2258 | { return regex_search(__s, __s + _Rx_traits::length(__s), __e, __f); } |
2259 | |
2260 | |
2261 | |
2262 | |
2263 | |
2264 | |
2265 | |
2266 | |
2267 | |
2268 | |
2269 | |
2270 | template<typename _Ch_traits, typename _String_allocator, |
2271 | typename _Ch_type, typename _Rx_traits> |
2272 | inline bool |
2273 | regex_search(const basic_string<_Ch_type, _Ch_traits, |
2274 | _String_allocator>& __s, |
2275 | const basic_regex<_Ch_type, _Rx_traits>& __e, |
2276 | regex_constants::match_flag_type __flags |
2277 | = regex_constants::match_default) |
2278 | { return regex_search(__s.begin(), __s.end(), __e, __flags); } |
2279 | |
2280 | |
2281 | |
2282 | |
2283 | |
2284 | |
2285 | |
2286 | |
2287 | |
2288 | |
2289 | |
2290 | |
2291 | |
2292 | template<typename _Ch_traits, typename _Ch_alloc, |
2293 | typename _Alloc, typename _Ch_type, |
2294 | typename _Rx_traits> |
2295 | inline bool |
2296 | regex_search(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s, |
2297 | match_results<typename basic_string<_Ch_type, |
2298 | _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>& __m, |
2299 | const basic_regex<_Ch_type, _Rx_traits>& __e, |
2300 | regex_constants::match_flag_type __f |
2301 | = regex_constants::match_default) |
2302 | { return regex_search(__s.begin(), __s.end(), __m, __e, __f); } |
2303 | |
2304 | |
2305 | |
2306 | |
2307 | template<typename _Ch_traits, typename _Ch_alloc, |
2308 | typename _Alloc, typename _Ch_type, |
2309 | typename _Rx_traits> |
2310 | bool |
2311 | regex_search(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>&&, |
2312 | match_results<typename basic_string<_Ch_type, |
2313 | _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>&, |
2314 | const basic_regex<_Ch_type, _Rx_traits>&, |
2315 | regex_constants::match_flag_type |
2316 | = regex_constants::match_default) = delete; |
2317 | |
2318 | |
2319 | |
2320 | |
2321 | |
2322 | |
2323 | |
2324 | |
2325 | |
2326 | |
2327 | |
2328 | |
2329 | |
2330 | |
2331 | |
2332 | template<typename _Out_iter, typename _Bi_iter, |
2333 | typename _Rx_traits, typename _Ch_type, |
2334 | typename _St, typename _Sa> |
2335 | inline _Out_iter |
2336 | regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last, |
2337 | const basic_regex<_Ch_type, _Rx_traits>& __e, |
2338 | const basic_string<_Ch_type, _St, _Sa>& __fmt, |
2339 | regex_constants::match_flag_type __flags |
2340 | = regex_constants::match_default) |
2341 | { |
2342 | return regex_replace(__out, __first, __last, __e, __fmt.c_str(), __flags); |
2343 | } |
2344 | |
2345 | |
2346 | |
2347 | |
2348 | |
2349 | |
2350 | |
2351 | |
2352 | |
2353 | |
2354 | |
2355 | |
2356 | |
2357 | |
2358 | template<typename _Out_iter, typename _Bi_iter, |
2359 | typename _Rx_traits, typename _Ch_type> |
2360 | _Out_iter |
2361 | regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last, |
2362 | const basic_regex<_Ch_type, _Rx_traits>& __e, |
2363 | const _Ch_type* __fmt, |
2364 | regex_constants::match_flag_type __flags |
2365 | = regex_constants::match_default); |
2366 | |
2367 | |
2368 | |
2369 | |
2370 | |
2371 | |
2372 | |
2373 | |
2374 | |
2375 | |
2376 | |
2377 | |
2378 | template<typename _Rx_traits, typename _Ch_type, |
2379 | typename _St, typename _Sa, typename _Fst, typename _Fsa> |
2380 | inline basic_string<_Ch_type, _St, _Sa> |
2381 | regex_replace(const basic_string<_Ch_type, _St, _Sa>& __s, |
2382 | const basic_regex<_Ch_type, _Rx_traits>& __e, |
2383 | const basic_string<_Ch_type, _Fst, _Fsa>& __fmt, |
2384 | regex_constants::match_flag_type __flags |
2385 | = regex_constants::match_default) |
2386 | { |
2387 | basic_string<_Ch_type, _St, _Sa> __result; |
2388 | regex_replace(std::back_inserter(__result), |
2389 | __s.begin(), __s.end(), __e, __fmt, __flags); |
2390 | return __result; |
2391 | } |
2392 | |
2393 | |
2394 | |
2395 | |
2396 | |
2397 | |
2398 | |
2399 | |
2400 | |
2401 | |
2402 | |
2403 | |
2404 | template<typename _Rx_traits, typename _Ch_type, |
2405 | typename _St, typename _Sa> |
2406 | inline basic_string<_Ch_type, _St, _Sa> |
2407 | regex_replace(const basic_string<_Ch_type, _St, _Sa>& __s, |
2408 | const basic_regex<_Ch_type, _Rx_traits>& __e, |
2409 | const _Ch_type* __fmt, |
2410 | regex_constants::match_flag_type __flags |
2411 | = regex_constants::match_default) |
2412 | { |
2413 | basic_string<_Ch_type, _St, _Sa> __result; |
2414 | regex_replace(std::back_inserter(__result), |
2415 | __s.begin(), __s.end(), __e, __fmt, __flags); |
2416 | return __result; |
2417 | } |
2418 | |
2419 | |
2420 | |
2421 | |
2422 | |
2423 | |
2424 | |
2425 | |
2426 | |
2427 | |
2428 | |
2429 | |
2430 | template<typename _Rx_traits, typename _Ch_type, |
2431 | typename _St, typename _Sa> |
2432 | inline basic_string<_Ch_type> |
2433 | regex_replace(const _Ch_type* __s, |
2434 | const basic_regex<_Ch_type, _Rx_traits>& __e, |
2435 | const basic_string<_Ch_type, _St, _Sa>& __fmt, |
2436 | regex_constants::match_flag_type __flags |
2437 | = regex_constants::match_default) |
2438 | { |
2439 | basic_string<_Ch_type> __result; |
2440 | regex_replace(std::back_inserter(__result), __s, |
2441 | __s + char_traits<_Ch_type>::length(__s), |
2442 | __e, __fmt, __flags); |
2443 | return __result; |
2444 | } |
2445 | |
2446 | |
2447 | |
2448 | |
2449 | |
2450 | |
2451 | |
2452 | |
2453 | |
2454 | |
2455 | |
2456 | |
2457 | template<typename _Rx_traits, typename _Ch_type> |
2458 | inline basic_string<_Ch_type> |
2459 | regex_replace(const _Ch_type* __s, |
2460 | const basic_regex<_Ch_type, _Rx_traits>& __e, |
2461 | const _Ch_type* __fmt, |
2462 | regex_constants::match_flag_type __flags |
2463 | = regex_constants::match_default) |
2464 | { |
2465 | basic_string<_Ch_type> __result; |
2466 | regex_replace(std::back_inserter(__result), __s, |
2467 | __s + char_traits<_Ch_type>::length(__s), |
2468 | __e, __fmt, __flags); |
2469 | return __result; |
2470 | } |
2471 | |
2472 | |
2473 | |
2474 | _GLIBCXX_BEGIN_NAMESPACE_CXX11 |
2475 | |
2476 | |
2477 | |
2478 | |
2479 | |
2480 | |
2481 | template<typename _Bi_iter, |
2482 | typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type, |
2483 | typename _Rx_traits = regex_traits<_Ch_type> > |
2484 | class regex_iterator |
2485 | { |
2486 | public: |
2487 | typedef basic_regex<_Ch_type, _Rx_traits> regex_type; |
2488 | typedef match_results<_Bi_iter> value_type; |
2489 | typedef std::ptrdiff_t difference_type; |
2490 | typedef const value_type* pointer; |
2491 | typedef const value_type& reference; |
2492 | typedef std::forward_iterator_tag iterator_category; |
2493 | |
2494 | |
2495 | |
2496 | |
2497 | |
2498 | regex_iterator() |
2499 | : _M_pregex() |
2500 | { } |
2501 | |
2502 | |
2503 | |
2504 | |
2505 | |
2506 | |
2507 | |
2508 | |
2509 | regex_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re, |
2510 | regex_constants::match_flag_type __m |
2511 | = regex_constants::match_default) |
2512 | : _M_begin(__a), _M_end(__b), _M_pregex(&__re), _M_flags(__m), _M_match() |
2513 | { |
2514 | if (!regex_search(_M_begin, _M_end, _M_match, *_M_pregex, _M_flags)) |
2515 | *this = regex_iterator(); |
2516 | } |
2517 | |
2518 | |
2519 | |
2520 | regex_iterator(_Bi_iter, _Bi_iter, const regex_type&&, |
2521 | regex_constants::match_flag_type |
2522 | = regex_constants::match_default) = delete; |
2523 | |
2524 | |
2525 | |
2526 | regex_iterator(const regex_iterator& __rhs) = default; |
2527 | |
2528 | |
2529 | |
2530 | |
2531 | regex_iterator& |
2532 | operator=(const regex_iterator& __rhs) = default; |
2533 | |
2534 | |
2535 | |
2536 | |
2537 | bool |
2538 | operator==(const regex_iterator& __rhs) const; |
2539 | |
2540 | |
2541 | |
2542 | |
2543 | bool |
2544 | operator!=(const regex_iterator& __rhs) const |
2545 | { return !(*this == __rhs); } |
2546 | |
2547 | |
2548 | |
2549 | |
2550 | const value_type& |
2551 | operator*() const |
2552 | { return _M_match; } |
2553 | |
2554 | |
2555 | |
2556 | |
2557 | const value_type* |
2558 | operator->() const |
2559 | { return &_M_match; } |
2560 | |
2561 | |
2562 | |
2563 | |
2564 | regex_iterator& |
2565 | operator++(); |
2566 | |
2567 | |
2568 | |
2569 | |
2570 | regex_iterator |
2571 | operator++(int) |
2572 | { |
2573 | auto __tmp = *this; |
2574 | ++(*this); |
2575 | return __tmp; |
2576 | } |
2577 | |
2578 | private: |
2579 | _Bi_iter _M_begin; |
2580 | _Bi_iter _M_end; |
2581 | const regex_type* _M_pregex; |
2582 | regex_constants::match_flag_type _M_flags; |
2583 | match_results<_Bi_iter> _M_match; |
2584 | }; |
2585 | |
2586 | typedef regex_iterator<const char*> cregex_iterator; |
2587 | typedef regex_iterator<string::const_iterator> sregex_iterator; |
2588 | #ifdef _GLIBCXX_USE_WCHAR_T |
2589 | typedef regex_iterator<const wchar_t*> wcregex_iterator; |
2590 | typedef regex_iterator<wstring::const_iterator> wsregex_iterator; |
2591 | #endif |
2592 | |
2593 | |
2594 | |
2595 | |
2596 | |
2597 | |
2598 | |
2599 | |
2600 | |
2601 | template<typename _Bi_iter, |
2602 | typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type, |
2603 | typename _Rx_traits = regex_traits<_Ch_type> > |
2604 | class regex_token_iterator |
2605 | { |
2606 | public: |
2607 | typedef basic_regex<_Ch_type, _Rx_traits> regex_type; |
2608 | typedef sub_match<_Bi_iter> value_type; |
2609 | typedef std::ptrdiff_t difference_type; |
2610 | typedef const value_type* pointer; |
2611 | typedef const value_type& reference; |
2612 | typedef std::forward_iterator_tag iterator_category; |
2613 | |
2614 | public: |
2615 | |
2616 | |
2617 | |
2618 | |
2619 | |
2620 | |
2621 | |
2622 | regex_token_iterator() |
2623 | : _M_position(), _M_subs(), _M_suffix(), _M_n(0), _M_result(nullptr), |
2624 | _M_has_m1(false) |
2625 | { } |
2626 | |
2627 | |
2628 | |
2629 | |
2630 | |
2631 | |
2632 | |
2633 | |
2634 | |
2635 | |
2636 | |
2637 | |
2638 | |
2639 | |
2640 | |
2641 | |
2642 | |
2643 | |
2644 | regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re, |
2645 | int __submatch = 0, |
2646 | regex_constants::match_flag_type __m |
2647 | = regex_constants::match_default) |
2648 | : _M_position(__a, __b, __re, __m), _M_subs(1, __submatch), _M_n(0) |
2649 | { _M_init(__a, __b); } |
2650 | |
2651 | |
2652 | |
2653 | |
2654 | |
2655 | |
2656 | |
2657 | |
2658 | |
2659 | |
2660 | regex_token_iterator(_Bi_iter __a, _Bi_iter __b, |
2661 | const regex_type& __re, |
2662 | const std::vector<int>& __submatches, |
2663 | regex_constants::match_flag_type __m |
2664 | = regex_constants::match_default) |
2665 | : _M_position(__a, __b, __re, __m), _M_subs(__submatches), _M_n(0) |
2666 | { _M_init(__a, __b); } |
2667 | |
2668 | |
2669 | |
2670 | |
2671 | |
2672 | |
2673 | |
2674 | |
2675 | |
2676 | |
2677 | regex_token_iterator(_Bi_iter __a, _Bi_iter __b, |
2678 | const regex_type& __re, |
2679 | initializer_list<int> __submatches, |
2680 | regex_constants::match_flag_type __m |
2681 | = regex_constants::match_default) |
2682 | : _M_position(__a, __b, __re, __m), _M_subs(__submatches), _M_n(0) |
2683 | { _M_init(__a, __b); } |
2684 | |
2685 | |
2686 | |
2687 | |
2688 | |
2689 | |
2690 | |
2691 | |
2692 | |
2693 | |
2694 | template<std::size_t _Nm> |
2695 | regex_token_iterator(_Bi_iter __a, _Bi_iter __b, |
2696 | const regex_type& __re, |
2697 | const int (&__submatches)[_Nm], |
2698 | regex_constants::match_flag_type __m |
2699 | = regex_constants::match_default) |
2700 | : _M_position(__a, __b, __re, __m), |
2701 | _M_subs(__submatches, __submatches + _Nm), _M_n(0) |
2702 | { _M_init(__a, __b); } |
2703 | |
2704 | |
2705 | |
2706 | regex_token_iterator(_Bi_iter, _Bi_iter, const regex_type&&, int = 0, |
2707 | regex_constants::match_flag_type = |
2708 | regex_constants::match_default) = delete; |
2709 | regex_token_iterator(_Bi_iter, _Bi_iter, const regex_type&&, |
2710 | const std::vector<int>&, |
2711 | regex_constants::match_flag_type = |
2712 | regex_constants::match_default) = delete; |
2713 | regex_token_iterator(_Bi_iter, _Bi_iter, const regex_type&&, |
2714 | initializer_list<int>, |
2715 | regex_constants::match_flag_type = |
2716 | regex_constants::match_default) = delete; |
2717 | template <std::size_t _Nm> |
2718 | regex_token_iterator(_Bi_iter, _Bi_iter, const regex_type&&, |
2719 | const int (&)[_Nm], |
2720 | regex_constants::match_flag_type = |
2721 | regex_constants::match_default) = delete; |
2722 | |
2723 | |
2724 | |
2725 | |
2726 | |
2727 | regex_token_iterator(const regex_token_iterator& __rhs) |
2728 | : _M_position(__rhs._M_position), _M_subs(__rhs._M_subs), |
2729 | _M_suffix(__rhs._M_suffix), _M_n(__rhs._M_n), _M_has_m1(__rhs._M_has_m1) |
2730 | { _M_normalize_result(); } |
2731 | |
2732 | |
2733 | |
2734 | |
2735 | |
2736 | regex_token_iterator& |
2737 | operator=(const regex_token_iterator& __rhs); |
2738 | |
2739 | |
2740 | |
2741 | |
2742 | bool |
2743 | operator==(const regex_token_iterator& __rhs) const; |
2744 | |
2745 | |
2746 | |
2747 | |
2748 | bool |
2749 | operator!=(const regex_token_iterator& __rhs) const |
2750 | { return !(*this == __rhs); } |
2751 | |
2752 | |
2753 | |
2754 | |
2755 | const value_type& |
2756 | operator*() const |
2757 | { return *_M_result; } |
2758 | |
2759 | |
2760 | |
2761 | |
2762 | const value_type* |
2763 | operator->() const |
2764 | { return _M_result; } |
2765 | |
2766 | |
2767 | |
2768 | |
2769 | regex_token_iterator& |
2770 | operator++(); |
2771 | |
2772 | |
2773 | |
2774 | |
2775 | regex_token_iterator |
2776 | operator++(int) |
2777 | { |
2778 | auto __tmp = *this; |
2779 | ++(*this); |
2780 | return __tmp; |
2781 | } |
2782 | |
2783 | private: |
2784 | typedef regex_iterator<_Bi_iter, _Ch_type, _Rx_traits> _Position; |
2785 | |
2786 | void |
2787 | _M_init(_Bi_iter __a, _Bi_iter __b); |
2788 | |
2789 | const value_type& |
2790 | _M_current_match() const |
2791 | { |
2792 | if (_M_subs[_M_n] == -1) |
2793 | return (*_M_position).prefix(); |
2794 | else |
2795 | return (*_M_position)[_M_subs[_M_n]]; |
2796 | } |
2797 | |
2798 | constexpr bool |
2799 | _M_end_of_seq() const |
2800 | { return _M_result == nullptr; } |
2801 | |
2802 | |
2803 | void |
2804 | _M_normalize_result() |
2805 | { |
2806 | if (_M_position != _Position()) |
2807 | _M_result = &_M_current_match(); |
2808 | else if (_M_has_m1) |
2809 | _M_result = &_M_suffix; |
2810 | else |
2811 | _M_result = nullptr; |
2812 | } |
2813 | |
2814 | _Position _M_position; |
2815 | std::vector<int> _M_subs; |
2816 | value_type _M_suffix; |
2817 | std::size_t _M_n; |
2818 | const value_type* _M_result; |
2819 | |
2820 | |
2821 | bool _M_has_m1; |
2822 | }; |
2823 | |
2824 | |
2825 | typedef regex_token_iterator<const char*> cregex_token_iterator; |
2826 | |
2827 | |
2828 | typedef regex_token_iterator<string::const_iterator> sregex_token_iterator; |
2829 | |
2830 | #ifdef _GLIBCXX_USE_WCHAR_T |
2831 | |
2832 | typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator; |
2833 | |
2834 | |
2835 | typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator; |
2836 | #endif |
2837 | |
2838 | |
2839 | |
2840 | _GLIBCXX_END_NAMESPACE_CXX11 |
2841 | _GLIBCXX_END_NAMESPACE_VERSION |
2842 | } |
2843 | |
2844 | #include <bits/regex.tcc> |
2845 | |