File indexing completed on 2025-01-18 09:51:25
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #ifndef BOOST_REGEX_V4_REGEX_ITERATOR_HPP
0020 #define BOOST_REGEX_V4_REGEX_ITERATOR_HPP
0021
0022 #include <boost/shared_ptr.hpp>
0023
0024 namespace boost{
0025
0026 #ifdef BOOST_MSVC
0027 #pragma warning(push)
0028 #pragma warning(disable: 4103)
0029 #endif
0030 #ifdef BOOST_HAS_ABI_HEADERS
0031 # include BOOST_ABI_PREFIX
0032 #endif
0033 #ifdef BOOST_MSVC
0034 #pragma warning(pop)
0035 #endif
0036
0037 template <class BidirectionalIterator,
0038 class charT,
0039 class traits>
0040 class regex_iterator_implementation
0041 {
0042 typedef basic_regex<charT, traits> regex_type;
0043
0044 match_results<BidirectionalIterator> what;
0045 BidirectionalIterator base;
0046 BidirectionalIterator end;
0047 const regex_type re;
0048 match_flag_type flags;
0049
0050 public:
0051 regex_iterator_implementation(const regex_type* p, BidirectionalIterator last, match_flag_type f)
0052 : base(), end(last), re(*p), flags(f){}
0053 regex_iterator_implementation(const regex_iterator_implementation& other)
0054 :what(other.what), base(other.base), end(other.end), re(other.re), flags(other.flags){}
0055 bool init(BidirectionalIterator first)
0056 {
0057 base = first;
0058 return regex_search(first, end, what, re, flags);
0059 }
0060 bool compare(const regex_iterator_implementation& that)
0061 {
0062 if(this == &that) return true;
0063 return (&re.get_data() == &that.re.get_data()) && (end == that.end) && (flags == that.flags) && (what[0].first == that.what[0].first) && (what[0].second == that.what[0].second);
0064 }
0065 const match_results<BidirectionalIterator>& get()
0066 { return what; }
0067 bool next()
0068 {
0069
0070
0071 BidirectionalIterator next_start = what[0].second;
0072 match_flag_type f(flags);
0073 if(!what.length() || (f & regex_constants::match_posix))
0074 f |= regex_constants::match_not_initial_null;
0075
0076
0077 bool result = regex_search(next_start, end, what, re, f, base);
0078 if(result)
0079 what.set_base(base);
0080 return result;
0081 }
0082 private:
0083 regex_iterator_implementation& operator=(const regex_iterator_implementation&);
0084 };
0085
0086 template <class BidirectionalIterator,
0087 class charT = BOOST_DEDUCED_TYPENAME BOOST_REGEX_DETAIL_NS::regex_iterator_traits<BidirectionalIterator>::value_type,
0088 class traits = regex_traits<charT> >
0089 class regex_iterator
0090 {
0091 private:
0092 typedef regex_iterator_implementation<BidirectionalIterator, charT, traits> impl;
0093 typedef shared_ptr<impl> pimpl;
0094 public:
0095 typedef basic_regex<charT, traits> regex_type;
0096 typedef match_results<BidirectionalIterator> value_type;
0097 typedef typename BOOST_REGEX_DETAIL_NS::regex_iterator_traits<BidirectionalIterator>::difference_type
0098 difference_type;
0099 typedef const value_type* pointer;
0100 typedef const value_type& reference;
0101 typedef std::forward_iterator_tag iterator_category;
0102
0103 regex_iterator(){}
0104 regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
0105 const regex_type& re,
0106 match_flag_type m = match_default)
0107 : pdata(new impl(&re, b, m))
0108 {
0109 if(!pdata->init(a))
0110 {
0111 pdata.reset();
0112 }
0113 }
0114 regex_iterator(const regex_iterator& that)
0115 : pdata(that.pdata) {}
0116 regex_iterator& operator=(const regex_iterator& that)
0117 {
0118 pdata = that.pdata;
0119 return *this;
0120 }
0121 bool operator==(const regex_iterator& that)const
0122 {
0123 if((pdata.get() == 0) || (that.pdata.get() == 0))
0124 return pdata.get() == that.pdata.get();
0125 return pdata->compare(*(that.pdata.get()));
0126 }
0127 bool operator!=(const regex_iterator& that)const
0128 { return !(*this == that); }
0129 const value_type& operator*()const
0130 { return pdata->get(); }
0131 const value_type* operator->()const
0132 { return &(pdata->get()); }
0133 regex_iterator& operator++()
0134 {
0135 cow();
0136 if(0 == pdata->next())
0137 {
0138 pdata.reset();
0139 }
0140 return *this;
0141 }
0142 regex_iterator operator++(int)
0143 {
0144 regex_iterator result(*this);
0145 ++(*this);
0146 return result;
0147 }
0148 private:
0149
0150 pimpl pdata;
0151
0152 void cow()
0153 {
0154
0155 if(pdata.get() && !pdata.unique())
0156 {
0157 pdata.reset(new impl(*(pdata.get())));
0158 }
0159 }
0160 };
0161
0162 typedef regex_iterator<const char*> cregex_iterator;
0163 typedef regex_iterator<std::string::const_iterator> sregex_iterator;
0164 #ifndef BOOST_NO_WREGEX
0165 typedef regex_iterator<const wchar_t*> wcregex_iterator;
0166 typedef regex_iterator<std::wstring::const_iterator> wsregex_iterator;
0167 #endif
0168
0169
0170 template <class charT, class traits>
0171 inline regex_iterator<const charT*, charT, traits> make_regex_iterator(const charT* p, const basic_regex<charT, traits>& e, regex_constants::match_flag_type m = regex_constants::match_default)
0172 {
0173 return regex_iterator<const charT*, charT, traits>(p, p+traits::length(p), e, m);
0174 }
0175 template <class charT, class traits, class ST, class SA>
0176 inline regex_iterator<typename std::basic_string<charT, ST, SA>::const_iterator, charT, traits> make_regex_iterator(const std::basic_string<charT, ST, SA>& p, const basic_regex<charT, traits>& e, regex_constants::match_flag_type m = regex_constants::match_default)
0177 {
0178 return regex_iterator<typename std::basic_string<charT, ST, SA>::const_iterator, charT, traits>(p.begin(), p.end(), e, m);
0179 }
0180
0181 #ifdef BOOST_MSVC
0182 #pragma warning(push)
0183 #pragma warning(disable: 4103)
0184 #endif
0185 #ifdef BOOST_HAS_ABI_HEADERS
0186 # include BOOST_ABI_SUFFIX
0187 #endif
0188 #ifdef BOOST_MSVC
0189 #pragma warning(pop)
0190 #endif
0191
0192 }
0193
0194 #endif
0195