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

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents c530137014c0
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 u32regex_token_iterator.hpp
Chris@16 15 * VERSION see <boost/version.hpp>
Chris@16 16 * DESCRIPTION: Provides u32regex_token_iterator implementation.
Chris@16 17 */
Chris@16 18
Chris@16 19 #ifndef BOOST_REGEX_V4_U32REGEX_TOKEN_ITERATOR_HPP
Chris@16 20 #define BOOST_REGEX_V4_U32REGEX_TOKEN_ITERATOR_HPP
Chris@16 21
Chris@16 22 #if (BOOST_WORKAROUND(__BORLANDC__, >= 0x560) && BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x570)))\
Chris@16 23 || BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
Chris@16 24 //
Chris@16 25 // Borland C++ Builder 6, and Visual C++ 6,
Chris@16 26 // can't cope with the array template constructor
Chris@16 27 // so we have a template member that will accept any type as
Chris@16 28 // argument, and then assert that is really is an array:
Chris@16 29 //
Chris@16 30 #include <boost/static_assert.hpp>
Chris@16 31 #include <boost/type_traits/is_array.hpp>
Chris@16 32 #endif
Chris@16 33
Chris@16 34 namespace boost{
Chris@16 35
Chris@16 36 #ifdef BOOST_HAS_ABI_HEADERS
Chris@16 37 # include BOOST_ABI_PREFIX
Chris@16 38 #endif
Chris@101 39 #ifdef BOOST_MSVC
Chris@16 40 # pragma warning(push)
Chris@16 41 # pragma warning(disable:4700)
Chris@16 42 #endif
Chris@16 43
Chris@16 44 template <class BidirectionalIterator>
Chris@16 45 class u32regex_token_iterator_implementation
Chris@16 46 {
Chris@16 47 typedef u32regex regex_type;
Chris@16 48 typedef sub_match<BidirectionalIterator> value_type;
Chris@16 49
Chris@16 50 match_results<BidirectionalIterator> what; // current match
Chris@16 51 BidirectionalIterator end; // end of search area
Chris@16 52 BidirectionalIterator base; // start of search area
Chris@16 53 const regex_type re; // the expression
Chris@16 54 match_flag_type flags; // match flags
Chris@16 55 value_type result; // the current string result
Chris@16 56 int N; // the current sub-expression being enumerated
Chris@16 57 std::vector<int> subs; // the sub-expressions to enumerate
Chris@16 58
Chris@16 59 public:
Chris@16 60 u32regex_token_iterator_implementation(const regex_type* p, BidirectionalIterator last, int sub, match_flag_type f)
Chris@16 61 : end(last), re(*p), flags(f){ subs.push_back(sub); }
Chris@16 62 u32regex_token_iterator_implementation(const regex_type* p, BidirectionalIterator last, const std::vector<int>& v, match_flag_type f)
Chris@16 63 : end(last), re(*p), flags(f), subs(v){}
Chris@101 64 #if (BOOST_WORKAROUND(__BORLANDC__, >= 0x560) && BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x570)))\
Chris@16 65 || BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) \
Chris@16 66 || BOOST_WORKAROUND(__HP_aCC, < 60700)
Chris@16 67 template <class T>
Chris@16 68 u32regex_token_iterator_implementation(const regex_type* p, BidirectionalIterator last, const T& submatches, match_flag_type f)
Chris@16 69 : end(last), re(*p), flags(f)
Chris@16 70 {
Chris@16 71 // assert that T really is an array:
Chris@16 72 BOOST_STATIC_ASSERT(::boost::is_array<T>::value);
Chris@16 73 const std::size_t array_size = sizeof(T) / sizeof(submatches[0]);
Chris@16 74 for(std::size_t i = 0; i < array_size; ++i)
Chris@16 75 {
Chris@16 76 subs.push_back(submatches[i]);
Chris@16 77 }
Chris@16 78 }
Chris@16 79 #else
Chris@16 80 template <std::size_t CN>
Chris@16 81 u32regex_token_iterator_implementation(const regex_type* p, BidirectionalIterator last, const int (&submatches)[CN], match_flag_type f)
Chris@16 82 : end(last), re(*p), flags(f)
Chris@16 83 {
Chris@16 84 for(std::size_t i = 0; i < CN; ++i)
Chris@16 85 {
Chris@16 86 subs.push_back(submatches[i]);
Chris@16 87 }
Chris@16 88 }
Chris@16 89 #endif
Chris@16 90
Chris@16 91 bool init(BidirectionalIterator first)
Chris@16 92 {
Chris@16 93 base = first;
Chris@16 94 N = 0;
Chris@16 95 if(u32regex_search(first, end, what, re, flags, base) == true)
Chris@16 96 {
Chris@16 97 N = 0;
Chris@16 98 result = ((subs[N] == -1) ? what.prefix() : what[(int)subs[N]]);
Chris@16 99 return true;
Chris@16 100 }
Chris@16 101 else if((subs[N] == -1) && (first != end))
Chris@16 102 {
Chris@16 103 result.first = first;
Chris@16 104 result.second = end;
Chris@16 105 result.matched = (first != end);
Chris@16 106 N = -1;
Chris@16 107 return true;
Chris@16 108 }
Chris@16 109 return false;
Chris@16 110 }
Chris@16 111 bool compare(const u32regex_token_iterator_implementation& that)
Chris@16 112 {
Chris@16 113 if(this == &that) return true;
Chris@16 114 return (&re.get_data() == &that.re.get_data())
Chris@16 115 && (end == that.end)
Chris@16 116 && (flags == that.flags)
Chris@16 117 && (N == that.N)
Chris@16 118 && (what[0].first == that.what[0].first)
Chris@16 119 && (what[0].second == that.what[0].second);
Chris@16 120 }
Chris@16 121 const value_type& get()
Chris@16 122 { return result; }
Chris@16 123 bool next()
Chris@16 124 {
Chris@16 125 if(N == -1)
Chris@16 126 return false;
Chris@16 127 if(N+1 < (int)subs.size())
Chris@16 128 {
Chris@16 129 ++N;
Chris@16 130 result =((subs[N] == -1) ? what.prefix() : what[subs[N]]);
Chris@16 131 return true;
Chris@16 132 }
Chris@16 133 //if(what.prefix().first != what[0].second)
Chris@16 134 // flags |= match_prev_avail | regex_constants::match_not_bob;
Chris@16 135 BidirectionalIterator last_end(what[0].second);
Chris@16 136 if(u32regex_search(last_end, end, what, re, ((what[0].first == what[0].second) ? flags | regex_constants::match_not_initial_null : flags), base))
Chris@16 137 {
Chris@16 138 N =0;
Chris@16 139 result =((subs[N] == -1) ? what.prefix() : what[subs[N]]);
Chris@16 140 return true;
Chris@16 141 }
Chris@16 142 else if((last_end != end) && (subs[0] == -1))
Chris@16 143 {
Chris@16 144 N =-1;
Chris@16 145 result.first = last_end;
Chris@16 146 result.second = end;
Chris@16 147 result.matched = (last_end != end);
Chris@16 148 return true;
Chris@16 149 }
Chris@16 150 return false;
Chris@16 151 }
Chris@16 152 private:
Chris@16 153 u32regex_token_iterator_implementation& operator=(const u32regex_token_iterator_implementation&);
Chris@16 154 };
Chris@16 155
Chris@16 156 template <class BidirectionalIterator>
Chris@16 157 class u32regex_token_iterator
Chris@16 158 #ifndef BOOST_NO_STD_ITERATOR
Chris@16 159 : public std::iterator<
Chris@16 160 std::forward_iterator_tag,
Chris@16 161 sub_match<BidirectionalIterator>,
Chris@16 162 typename re_detail::regex_iterator_traits<BidirectionalIterator>::difference_type,
Chris@16 163 const sub_match<BidirectionalIterator>*,
Chris@16 164 const sub_match<BidirectionalIterator>& >
Chris@16 165 #endif
Chris@16 166 {
Chris@16 167 private:
Chris@16 168 typedef u32regex_token_iterator_implementation<BidirectionalIterator> impl;
Chris@16 169 typedef shared_ptr<impl> pimpl;
Chris@16 170 public:
Chris@16 171 typedef u32regex regex_type;
Chris@16 172 typedef sub_match<BidirectionalIterator> value_type;
Chris@16 173 typedef typename re_detail::regex_iterator_traits<BidirectionalIterator>::difference_type
Chris@16 174 difference_type;
Chris@16 175 typedef const value_type* pointer;
Chris@16 176 typedef const value_type& reference;
Chris@16 177 typedef std::forward_iterator_tag iterator_category;
Chris@16 178
Chris@16 179 u32regex_token_iterator(){}
Chris@16 180 u32regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, const regex_type& re,
Chris@16 181 int submatch = 0, match_flag_type m = match_default)
Chris@16 182 : pdata(new impl(&re, b, submatch, m))
Chris@16 183 {
Chris@16 184 if(!pdata->init(a))
Chris@16 185 pdata.reset();
Chris@16 186 }
Chris@16 187 u32regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, const regex_type& re,
Chris@16 188 const std::vector<int>& submatches, match_flag_type m = match_default)
Chris@16 189 : pdata(new impl(&re, b, submatches, m))
Chris@16 190 {
Chris@16 191 if(!pdata->init(a))
Chris@16 192 pdata.reset();
Chris@16 193 }
Chris@101 194 #if (BOOST_WORKAROUND(__BORLANDC__, >= 0x560) && BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x570)))\
Chris@16 195 || BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) \
Chris@16 196 || BOOST_WORKAROUND(__HP_aCC, < 60700)
Chris@16 197 template <class T>
Chris@16 198 u32regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, const regex_type& re,
Chris@16 199 const T& submatches, match_flag_type m = match_default)
Chris@16 200 : pdata(new impl(&re, b, submatches, m))
Chris@16 201 {
Chris@16 202 if(!pdata->init(a))
Chris@16 203 pdata.reset();
Chris@16 204 }
Chris@16 205 #else
Chris@16 206 template <std::size_t N>
Chris@16 207 u32regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, const regex_type& re,
Chris@16 208 const int (&submatches)[N], match_flag_type m = match_default)
Chris@16 209 : pdata(new impl(&re, b, submatches, m))
Chris@16 210 {
Chris@16 211 if(!pdata->init(a))
Chris@16 212 pdata.reset();
Chris@16 213 }
Chris@16 214 #endif
Chris@16 215 u32regex_token_iterator(const u32regex_token_iterator& that)
Chris@16 216 : pdata(that.pdata) {}
Chris@16 217 u32regex_token_iterator& operator=(const u32regex_token_iterator& that)
Chris@16 218 {
Chris@16 219 pdata = that.pdata;
Chris@16 220 return *this;
Chris@16 221 }
Chris@16 222 bool operator==(const u32regex_token_iterator& that)const
Chris@16 223 {
Chris@16 224 if((pdata.get() == 0) || (that.pdata.get() == 0))
Chris@16 225 return pdata.get() == that.pdata.get();
Chris@16 226 return pdata->compare(*(that.pdata.get()));
Chris@16 227 }
Chris@16 228 bool operator!=(const u32regex_token_iterator& that)const
Chris@16 229 { return !(*this == that); }
Chris@16 230 const value_type& operator*()const
Chris@16 231 { return pdata->get(); }
Chris@16 232 const value_type* operator->()const
Chris@16 233 { return &(pdata->get()); }
Chris@16 234 u32regex_token_iterator& operator++()
Chris@16 235 {
Chris@16 236 cow();
Chris@16 237 if(0 == pdata->next())
Chris@16 238 {
Chris@16 239 pdata.reset();
Chris@16 240 }
Chris@16 241 return *this;
Chris@16 242 }
Chris@16 243 u32regex_token_iterator operator++(int)
Chris@16 244 {
Chris@16 245 u32regex_token_iterator result(*this);
Chris@16 246 ++(*this);
Chris@16 247 return result;
Chris@16 248 }
Chris@16 249 private:
Chris@16 250
Chris@16 251 pimpl pdata;
Chris@16 252
Chris@16 253 void cow()
Chris@16 254 {
Chris@16 255 // copy-on-write
Chris@16 256 if(pdata.get() && !pdata.unique())
Chris@16 257 {
Chris@16 258 pdata.reset(new impl(*(pdata.get())));
Chris@16 259 }
Chris@16 260 }
Chris@16 261 };
Chris@16 262
Chris@16 263 typedef u32regex_token_iterator<const char*> utf8regex_token_iterator;
Chris@16 264 typedef u32regex_token_iterator<const UChar*> utf16regex_token_iterator;
Chris@16 265 typedef u32regex_token_iterator<const UChar32*> utf32regex_token_iterator;
Chris@16 266
Chris@16 267 // construction from an integral sub_match state_id:
Chris@16 268 inline u32regex_token_iterator<const char*> make_u32regex_token_iterator(const char* p, const u32regex& e, int submatch = 0, regex_constants::match_flag_type m = regex_constants::match_default)
Chris@16 269 {
Chris@16 270 return u32regex_token_iterator<const char*>(p, p+std::strlen(p), e, submatch, m);
Chris@16 271 }
Chris@16 272 #ifndef BOOST_NO_WREGEX
Chris@16 273 inline u32regex_token_iterator<const wchar_t*> make_u32regex_token_iterator(const wchar_t* p, const u32regex& e, int submatch = 0, regex_constants::match_flag_type m = regex_constants::match_default)
Chris@16 274 {
Chris@16 275 return u32regex_token_iterator<const wchar_t*>(p, p+std::wcslen(p), e, submatch, m);
Chris@16 276 }
Chris@16 277 #endif
Chris@16 278 #if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2)
Chris@16 279 inline u32regex_token_iterator<const UChar*> make_u32regex_token_iterator(const UChar* p, const u32regex& e, int submatch = 0, regex_constants::match_flag_type m = regex_constants::match_default)
Chris@16 280 {
Chris@16 281 return u32regex_token_iterator<const UChar*>(p, p+u_strlen(p), e, submatch, m);
Chris@16 282 }
Chris@16 283 #endif
Chris@16 284 template <class charT, class Traits, class Alloc>
Chris@16 285 inline u32regex_token_iterator<typename std::basic_string<charT, Traits, Alloc>::const_iterator> make_u32regex_token_iterator(const std::basic_string<charT, Traits, Alloc>& p, const u32regex& e, int submatch = 0, regex_constants::match_flag_type m = regex_constants::match_default)
Chris@16 286 {
Chris@16 287 typedef typename std::basic_string<charT, Traits, Alloc>::const_iterator iter_type;
Chris@16 288 return u32regex_token_iterator<iter_type>(p.begin(), p.end(), e, submatch, m);
Chris@16 289 }
Chris@16 290 inline u32regex_token_iterator<const UChar*> make_u32regex_token_iterator(const U_NAMESPACE_QUALIFIER UnicodeString& s, const u32regex& e, int submatch = 0, regex_constants::match_flag_type m = regex_constants::match_default)
Chris@16 291 {
Chris@16 292 return u32regex_token_iterator<const UChar*>(s.getBuffer(), s.getBuffer() + s.length(), e, submatch, m);
Chris@16 293 }
Chris@16 294
Chris@16 295 // construction from a reference to an array:
Chris@16 296 template <std::size_t N>
Chris@16 297 inline u32regex_token_iterator<const char*> make_u32regex_token_iterator(const char* p, const u32regex& e, const int (&submatch)[N], regex_constants::match_flag_type m = regex_constants::match_default)
Chris@16 298 {
Chris@16 299 return u32regex_token_iterator<const char*>(p, p+std::strlen(p), e, submatch, m);
Chris@16 300 }
Chris@16 301 #ifndef BOOST_NO_WREGEX
Chris@16 302 template <std::size_t N>
Chris@16 303 inline u32regex_token_iterator<const wchar_t*> make_u32regex_token_iterator(const wchar_t* p, const u32regex& e, const int (&submatch)[N], regex_constants::match_flag_type m = regex_constants::match_default)
Chris@16 304 {
Chris@16 305 return u32regex_token_iterator<const wchar_t*>(p, p+std::wcslen(p), e, submatch, m);
Chris@16 306 }
Chris@16 307 #endif
Chris@16 308 #if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2)
Chris@16 309 template <std::size_t N>
Chris@16 310 inline u32regex_token_iterator<const UChar*> make_u32regex_token_iterator(const UChar* p, const u32regex& e, const int (&submatch)[N], regex_constants::match_flag_type m = regex_constants::match_default)
Chris@16 311 {
Chris@16 312 return u32regex_token_iterator<const UChar*>(p, p+u_strlen(p), e, submatch, m);
Chris@16 313 }
Chris@16 314 #endif
Chris@16 315 template <class charT, class Traits, class Alloc, std::size_t N>
Chris@16 316 inline u32regex_token_iterator<typename std::basic_string<charT, Traits, Alloc>::const_iterator> make_u32regex_token_iterator(const std::basic_string<charT, Traits, Alloc>& p, const u32regex& e, const int (&submatch)[N], regex_constants::match_flag_type m = regex_constants::match_default)
Chris@16 317 {
Chris@16 318 typedef typename std::basic_string<charT, Traits, Alloc>::const_iterator iter_type;
Chris@16 319 return u32regex_token_iterator<iter_type>(p.begin(), p.end(), e, submatch, m);
Chris@16 320 }
Chris@16 321 template <std::size_t N>
Chris@16 322 inline u32regex_token_iterator<const UChar*> make_u32regex_token_iterator(const U_NAMESPACE_QUALIFIER UnicodeString& s, const u32regex& e, const int (&submatch)[N], regex_constants::match_flag_type m = regex_constants::match_default)
Chris@16 323 {
Chris@16 324 return u32regex_token_iterator<const UChar*>(s.getBuffer(), s.getBuffer() + s.length(), e, submatch, m);
Chris@16 325 }
Chris@16 326
Chris@16 327 // construction from a vector of sub_match state_id's:
Chris@16 328 inline u32regex_token_iterator<const char*> make_u32regex_token_iterator(const char* p, const u32regex& e, const std::vector<int>& submatch, regex_constants::match_flag_type m = regex_constants::match_default)
Chris@16 329 {
Chris@16 330 return u32regex_token_iterator<const char*>(p, p+std::strlen(p), e, submatch, m);
Chris@16 331 }
Chris@16 332 #ifndef BOOST_NO_WREGEX
Chris@16 333 inline u32regex_token_iterator<const wchar_t*> make_u32regex_token_iterator(const wchar_t* p, const u32regex& e, const std::vector<int>& submatch, regex_constants::match_flag_type m = regex_constants::match_default)
Chris@16 334 {
Chris@16 335 return u32regex_token_iterator<const wchar_t*>(p, p+std::wcslen(p), e, submatch, m);
Chris@16 336 }
Chris@16 337 #endif
Chris@16 338 #if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2)
Chris@16 339 inline u32regex_token_iterator<const UChar*> make_u32regex_token_iterator(const UChar* p, const u32regex& e, const std::vector<int>& submatch, regex_constants::match_flag_type m = regex_constants::match_default)
Chris@16 340 {
Chris@16 341 return u32regex_token_iterator<const UChar*>(p, p+u_strlen(p), e, submatch, m);
Chris@16 342 }
Chris@16 343 #endif
Chris@16 344 template <class charT, class Traits, class Alloc>
Chris@16 345 inline u32regex_token_iterator<typename std::basic_string<charT, Traits, Alloc>::const_iterator> make_u32regex_token_iterator(const std::basic_string<charT, Traits, Alloc>& p, const u32regex& e, const std::vector<int>& submatch, regex_constants::match_flag_type m = regex_constants::match_default)
Chris@16 346 {
Chris@16 347 typedef typename std::basic_string<charT, Traits, Alloc>::const_iterator iter_type;
Chris@16 348 return u32regex_token_iterator<iter_type>(p.begin(), p.end(), e, submatch, m);
Chris@16 349 }
Chris@16 350 inline u32regex_token_iterator<const UChar*> make_u32regex_token_iterator(const U_NAMESPACE_QUALIFIER UnicodeString& s, const u32regex& e, const std::vector<int>& submatch, regex_constants::match_flag_type m = regex_constants::match_default)
Chris@16 351 {
Chris@16 352 return u32regex_token_iterator<const UChar*>(s.getBuffer(), s.getBuffer() + s.length(), e, submatch, m);
Chris@16 353 }
Chris@16 354
Chris@101 355 #ifdef BOOST_MSVC
Chris@16 356 # pragma warning(pop)
Chris@16 357 #endif
Chris@16 358 #ifdef BOOST_HAS_ABI_HEADERS
Chris@16 359 # include BOOST_ABI_SUFFIX
Chris@16 360 #endif
Chris@16 361
Chris@16 362 } // namespace boost
Chris@16 363
Chris@16 364 #endif // BOOST_REGEX_V4_REGEX_TOKEN_ITERATOR_HPP
Chris@16 365
Chris@16 366
Chris@16 367
Chris@16 368