annotate DEPENDENCIES/generic/include/boost/regex/v4/regex_iterator.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 /*
Chris@16 2 *
Chris@16 3 * Copyright (c) 2003
Chris@16 4 * John Maddock
Chris@16 5 *
Chris@16 6 * Use, modification and distribution are subject to the
Chris@16 7 * Boost Software License, Version 1.0. (See accompanying file
Chris@16 8 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 9 *
Chris@16 10 */
Chris@16 11
Chris@16 12 /*
Chris@16 13 * LOCATION: see http://www.boost.org for most recent version.
Chris@16 14 * FILE regex_iterator.hpp
Chris@16 15 * VERSION see <boost/version.hpp>
Chris@16 16 * DESCRIPTION: Provides regex_iterator implementation.
Chris@16 17 */
Chris@16 18
Chris@16 19 #ifndef BOOST_REGEX_V4_REGEX_ITERATOR_HPP
Chris@16 20 #define BOOST_REGEX_V4_REGEX_ITERATOR_HPP
Chris@16 21
Chris@16 22 #include <boost/shared_ptr.hpp>
Chris@16 23
Chris@16 24 namespace boost{
Chris@16 25
Chris@16 26 #ifdef BOOST_MSVC
Chris@16 27 #pragma warning(push)
Chris@16 28 #pragma warning(disable: 4103)
Chris@16 29 #endif
Chris@16 30 #ifdef BOOST_HAS_ABI_HEADERS
Chris@16 31 # include BOOST_ABI_PREFIX
Chris@16 32 #endif
Chris@16 33 #ifdef BOOST_MSVC
Chris@16 34 #pragma warning(pop)
Chris@16 35 #endif
Chris@16 36
Chris@16 37 template <class BidirectionalIterator,
Chris@16 38 class charT,
Chris@16 39 class traits>
Chris@16 40 class regex_iterator_implementation
Chris@16 41 {
Chris@16 42 typedef basic_regex<charT, traits> regex_type;
Chris@16 43
Chris@16 44 match_results<BidirectionalIterator> what; // current match
Chris@16 45 BidirectionalIterator base; // start of sequence
Chris@16 46 BidirectionalIterator end; // end of sequence
Chris@16 47 const regex_type re; // the expression
Chris@16 48 match_flag_type flags; // flags for matching
Chris@16 49
Chris@16 50 public:
Chris@16 51 regex_iterator_implementation(const regex_type* p, BidirectionalIterator last, match_flag_type f)
Chris@16 52 : base(), end(last), re(*p), flags(f){}
Chris@16 53 bool init(BidirectionalIterator first)
Chris@16 54 {
Chris@16 55 base = first;
Chris@16 56 return regex_search(first, end, what, re, flags);
Chris@16 57 }
Chris@16 58 bool compare(const regex_iterator_implementation& that)
Chris@16 59 {
Chris@16 60 if(this == &that) return true;
Chris@16 61 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);
Chris@16 62 }
Chris@16 63 const match_results<BidirectionalIterator>& get()
Chris@16 64 { return what; }
Chris@16 65 bool next()
Chris@16 66 {
Chris@16 67 //if(what.prefix().first != what[0].second)
Chris@16 68 // flags |= match_prev_avail;
Chris@16 69 BidirectionalIterator next_start = what[0].second;
Chris@16 70 match_flag_type f(flags);
Chris@16 71 if(!what.length() || (f & regex_constants::match_posix))
Chris@16 72 f |= regex_constants::match_not_initial_null;
Chris@16 73 //if(base != next_start)
Chris@16 74 // f |= regex_constants::match_not_bob;
Chris@16 75 bool result = regex_search(next_start, end, what, re, f, base);
Chris@16 76 if(result)
Chris@16 77 what.set_base(base);
Chris@16 78 return result;
Chris@16 79 }
Chris@16 80 private:
Chris@16 81 regex_iterator_implementation& operator=(const regex_iterator_implementation&);
Chris@16 82 };
Chris@16 83
Chris@16 84 template <class BidirectionalIterator,
Chris@16 85 class charT = BOOST_DEDUCED_TYPENAME re_detail::regex_iterator_traits<BidirectionalIterator>::value_type,
Chris@16 86 class traits = regex_traits<charT> >
Chris@16 87 class regex_iterator
Chris@16 88 #ifndef BOOST_NO_STD_ITERATOR
Chris@16 89 : public std::iterator<
Chris@16 90 std::forward_iterator_tag,
Chris@16 91 match_results<BidirectionalIterator>,
Chris@16 92 typename re_detail::regex_iterator_traits<BidirectionalIterator>::difference_type,
Chris@16 93 const match_results<BidirectionalIterator>*,
Chris@16 94 const match_results<BidirectionalIterator>& >
Chris@16 95 #endif
Chris@16 96 {
Chris@16 97 private:
Chris@16 98 typedef regex_iterator_implementation<BidirectionalIterator, charT, traits> impl;
Chris@16 99 typedef shared_ptr<impl> pimpl;
Chris@16 100 public:
Chris@16 101 typedef basic_regex<charT, traits> regex_type;
Chris@16 102 typedef match_results<BidirectionalIterator> value_type;
Chris@16 103 typedef typename re_detail::regex_iterator_traits<BidirectionalIterator>::difference_type
Chris@16 104 difference_type;
Chris@16 105 typedef const value_type* pointer;
Chris@16 106 typedef const value_type& reference;
Chris@16 107 typedef std::forward_iterator_tag iterator_category;
Chris@16 108
Chris@16 109 regex_iterator(){}
Chris@16 110 regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
Chris@16 111 const regex_type& re,
Chris@16 112 match_flag_type m = match_default)
Chris@16 113 : pdata(new impl(&re, b, m))
Chris@16 114 {
Chris@16 115 if(!pdata->init(a))
Chris@16 116 {
Chris@16 117 pdata.reset();
Chris@16 118 }
Chris@16 119 }
Chris@16 120 regex_iterator(const regex_iterator& that)
Chris@16 121 : pdata(that.pdata) {}
Chris@16 122 regex_iterator& operator=(const regex_iterator& that)
Chris@16 123 {
Chris@16 124 pdata = that.pdata;
Chris@16 125 return *this;
Chris@16 126 }
Chris@16 127 bool operator==(const regex_iterator& that)const
Chris@16 128 {
Chris@16 129 if((pdata.get() == 0) || (that.pdata.get() == 0))
Chris@16 130 return pdata.get() == that.pdata.get();
Chris@16 131 return pdata->compare(*(that.pdata.get()));
Chris@16 132 }
Chris@16 133 bool operator!=(const regex_iterator& that)const
Chris@16 134 { return !(*this == that); }
Chris@16 135 const value_type& operator*()const
Chris@16 136 { return pdata->get(); }
Chris@16 137 const value_type* operator->()const
Chris@16 138 { return &(pdata->get()); }
Chris@16 139 regex_iterator& operator++()
Chris@16 140 {
Chris@16 141 cow();
Chris@16 142 if(0 == pdata->next())
Chris@16 143 {
Chris@16 144 pdata.reset();
Chris@16 145 }
Chris@16 146 return *this;
Chris@16 147 }
Chris@16 148 regex_iterator operator++(int)
Chris@16 149 {
Chris@16 150 regex_iterator result(*this);
Chris@16 151 ++(*this);
Chris@16 152 return result;
Chris@16 153 }
Chris@16 154 private:
Chris@16 155
Chris@16 156 pimpl pdata;
Chris@16 157
Chris@16 158 void cow()
Chris@16 159 {
Chris@16 160 // copy-on-write
Chris@16 161 if(pdata.get() && !pdata.unique())
Chris@16 162 {
Chris@16 163 pdata.reset(new impl(*(pdata.get())));
Chris@16 164 }
Chris@16 165 }
Chris@16 166 };
Chris@16 167
Chris@16 168 typedef regex_iterator<const char*> cregex_iterator;
Chris@16 169 typedef regex_iterator<std::string::const_iterator> sregex_iterator;
Chris@16 170 #ifndef BOOST_NO_WREGEX
Chris@16 171 typedef regex_iterator<const wchar_t*> wcregex_iterator;
Chris@16 172 typedef regex_iterator<std::wstring::const_iterator> wsregex_iterator;
Chris@16 173 #endif
Chris@16 174
Chris@16 175 // make_regex_iterator:
Chris@16 176 template <class charT, class traits>
Chris@16 177 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)
Chris@16 178 {
Chris@16 179 return regex_iterator<const charT*, charT, traits>(p, p+traits::length(p), e, m);
Chris@16 180 }
Chris@16 181 template <class charT, class traits, class ST, class SA>
Chris@16 182 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)
Chris@16 183 {
Chris@16 184 return regex_iterator<typename std::basic_string<charT, ST, SA>::const_iterator, charT, traits>(p.begin(), p.end(), e, m);
Chris@16 185 }
Chris@16 186
Chris@16 187 #ifdef BOOST_MSVC
Chris@16 188 #pragma warning(push)
Chris@16 189 #pragma warning(disable: 4103)
Chris@16 190 #endif
Chris@16 191 #ifdef BOOST_HAS_ABI_HEADERS
Chris@16 192 # include BOOST_ABI_SUFFIX
Chris@16 193 #endif
Chris@16 194 #ifdef BOOST_MSVC
Chris@16 195 #pragma warning(pop)
Chris@16 196 #endif
Chris@16 197
Chris@16 198 } // namespace boost
Chris@16 199
Chris@16 200 #endif // BOOST_REGEX_V4_REGEX_ITERATOR_HPP
Chris@16 201