Jeff Thompson | 86b6d64 | 2013-10-17 15:01:56 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (c) 1998-2002 |
| 4 | * John Maddock |
| 5 | * |
| 6 | * Use, modification and distribution are subject to the |
| 7 | * Boost Software License, Version 1.0. (See accompanying file |
| 8 | * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 9 | * |
| 10 | */ |
| 11 | |
| 12 | /* |
| 13 | * LOCATION: see http://www.boost.org for most recent version. |
| 14 | * FILE sub_match.cpp |
| 15 | * VERSION see <ndnboost/version.hpp> |
| 16 | * DESCRIPTION: Declares template class sub_match. |
| 17 | */ |
| 18 | |
| 19 | #ifndef NDNBOOST_REGEX_V4_SUB_MATCH_HPP |
| 20 | #define NDNBOOST_REGEX_V4_SUB_MATCH_HPP |
| 21 | |
| 22 | #ifdef NDNBOOST_MSVC |
| 23 | #pragma warning(push) |
| 24 | #pragma warning(disable: 4103) |
| 25 | #endif |
| 26 | #ifdef NDNBOOST_HAS_ABI_HEADERS |
| 27 | # include NDNBOOST_ABI_PREFIX |
| 28 | #endif |
| 29 | #ifdef NDNBOOST_MSVC |
| 30 | #pragma warning(pop) |
| 31 | #endif |
| 32 | |
| 33 | namespace ndnboost{ |
| 34 | |
| 35 | template <class BidiIterator> |
| 36 | struct sub_match : public std::pair<BidiIterator, BidiIterator> |
| 37 | { |
| 38 | typedef typename re_detail::regex_iterator_traits<BidiIterator>::value_type value_type; |
| 39 | #if defined(NDNBOOST_NO_STD_ITERATOR_TRAITS) || defined(NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) |
| 40 | typedef std::ptrdiff_t difference_type; |
| 41 | #else |
| 42 | typedef typename re_detail::regex_iterator_traits<BidiIterator>::difference_type difference_type; |
| 43 | #endif |
| 44 | typedef BidiIterator iterator_type; |
| 45 | typedef BidiIterator iterator; |
| 46 | typedef BidiIterator const_iterator; |
| 47 | |
| 48 | bool matched; |
| 49 | |
| 50 | sub_match() : std::pair<BidiIterator, BidiIterator>(), matched(false) {} |
| 51 | sub_match(BidiIterator i) : std::pair<BidiIterator, BidiIterator>(i, i), matched(false) {} |
| 52 | #if !defined(NDNBOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS)\ |
| 53 | && !NDNBOOST_WORKAROUND(NDNBOOST_MSVC, < 1310)\ |
| 54 | && !NDNBOOST_WORKAROUND(__BORLANDC__, <= 0x0551)\ |
| 55 | && !NDNBOOST_WORKAROUND(__DECCXX_VER, NDNBOOST_TESTED_AT(60590042)) |
| 56 | template <class T, class A> |
| 57 | operator std::basic_string<value_type, T, A> ()const |
| 58 | { |
| 59 | return matched ? std::basic_string<value_type, T, A>(this->first, this->second) : std::basic_string<value_type, T, A>(); |
| 60 | } |
| 61 | #else |
| 62 | operator std::basic_string<value_type> ()const |
| 63 | { |
| 64 | return str(); |
| 65 | } |
| 66 | #endif |
| 67 | difference_type NDNBOOST_REGEX_CALL length()const |
| 68 | { |
| 69 | difference_type n = matched ? ::ndnboost::re_detail::distance((BidiIterator)this->first, (BidiIterator)this->second) : 0; |
| 70 | return n; |
| 71 | } |
| 72 | std::basic_string<value_type> str()const |
| 73 | { |
| 74 | std::basic_string<value_type> result; |
| 75 | if(matched) |
| 76 | { |
| 77 | std::size_t len = ::ndnboost::re_detail::distance((BidiIterator)this->first, (BidiIterator)this->second); |
| 78 | result.reserve(len); |
| 79 | BidiIterator i = this->first; |
| 80 | while(i != this->second) |
| 81 | { |
| 82 | result.append(1, *i); |
| 83 | ++i; |
| 84 | } |
| 85 | } |
| 86 | return result; |
| 87 | } |
| 88 | int compare(const sub_match& s)const |
| 89 | { |
| 90 | if(matched != s.matched) |
| 91 | return static_cast<int>(matched) - static_cast<int>(s.matched); |
| 92 | return str().compare(s.str()); |
| 93 | } |
| 94 | int compare(const std::basic_string<value_type>& s)const |
| 95 | { |
| 96 | return str().compare(s); |
| 97 | } |
| 98 | int compare(const value_type* p)const |
| 99 | { |
| 100 | return str().compare(p); |
| 101 | } |
| 102 | |
| 103 | bool operator==(const sub_match& that)const |
| 104 | { return compare(that) == 0; } |
| 105 | bool NDNBOOST_REGEX_CALL operator !=(const sub_match& that)const |
| 106 | { return compare(that) != 0; } |
| 107 | bool operator<(const sub_match& that)const |
| 108 | { return compare(that) < 0; } |
| 109 | bool operator>(const sub_match& that)const |
| 110 | { return compare(that) > 0; } |
| 111 | bool operator<=(const sub_match& that)const |
| 112 | { return compare(that) <= 0; } |
| 113 | bool operator>=(const sub_match& that)const |
| 114 | { return compare(that) >= 0; } |
| 115 | |
| 116 | #ifdef NDNBOOST_REGEX_MATCH_EXTRA |
| 117 | typedef std::vector<sub_match<BidiIterator> > capture_sequence_type; |
| 118 | |
| 119 | const capture_sequence_type& captures()const |
| 120 | { |
| 121 | if(!m_captures) |
| 122 | m_captures.reset(new capture_sequence_type()); |
| 123 | return *m_captures; |
| 124 | } |
| 125 | // |
| 126 | // Private implementation API: DO NOT USE! |
| 127 | // |
| 128 | capture_sequence_type& get_captures()const |
| 129 | { |
| 130 | if(!m_captures) |
| 131 | m_captures.reset(new capture_sequence_type()); |
| 132 | return *m_captures; |
| 133 | } |
| 134 | |
| 135 | private: |
| 136 | mutable ndnboost::scoped_ptr<capture_sequence_type> m_captures; |
| 137 | public: |
| 138 | |
| 139 | #endif |
| 140 | sub_match(const sub_match& that, bool |
| 141 | #ifdef NDNBOOST_REGEX_MATCH_EXTRA |
| 142 | deep_copy |
| 143 | #endif |
| 144 | = true |
| 145 | ) |
| 146 | : std::pair<BidiIterator, BidiIterator>(that), |
| 147 | matched(that.matched) |
| 148 | { |
| 149 | #ifdef NDNBOOST_REGEX_MATCH_EXTRA |
| 150 | if(that.m_captures) |
| 151 | if(deep_copy) |
| 152 | m_captures.reset(new capture_sequence_type(*(that.m_captures))); |
| 153 | #endif |
| 154 | } |
| 155 | sub_match& operator=(const sub_match& that) |
| 156 | { |
| 157 | this->first = that.first; |
| 158 | this->second = that.second; |
| 159 | matched = that.matched; |
| 160 | #ifdef NDNBOOST_REGEX_MATCH_EXTRA |
| 161 | if(that.m_captures) |
| 162 | get_captures() = *(that.m_captures); |
| 163 | #endif |
| 164 | return *this; |
| 165 | } |
| 166 | |
| 167 | |
| 168 | #ifdef NDNBOOST_OLD_REGEX_H |
| 169 | // |
| 170 | // the following are deprecated, do not use!! |
| 171 | // |
| 172 | operator int()const; |
| 173 | operator unsigned int()const; |
| 174 | operator short()const |
| 175 | { |
| 176 | return (short)(int)(*this); |
| 177 | } |
| 178 | operator unsigned short()const |
| 179 | { |
| 180 | return (unsigned short)(unsigned int)(*this); |
| 181 | } |
| 182 | #endif |
| 183 | }; |
| 184 | |
| 185 | typedef sub_match<const char*> csub_match; |
| 186 | typedef sub_match<std::string::const_iterator> ssub_match; |
| 187 | #ifndef NDNBOOST_NO_WREGEX |
| 188 | typedef sub_match<const wchar_t*> wcsub_match; |
| 189 | typedef sub_match<std::wstring::const_iterator> wssub_match; |
| 190 | #endif |
| 191 | |
| 192 | // comparison to std::basic_string<> part 1: |
| 193 | template <class RandomAccessIterator, class traits, class Allocator> |
| 194 | inline bool operator == (const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s, |
| 195 | const sub_match<RandomAccessIterator>& m) |
| 196 | { return s.compare(m.str()) == 0; } |
| 197 | template <class RandomAccessIterator, class traits, class Allocator> |
| 198 | inline bool operator != (const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s, |
| 199 | const sub_match<RandomAccessIterator>& m) |
| 200 | { return s.compare(m.str()) != 0; } |
| 201 | template <class RandomAccessIterator, class traits, class Allocator> |
| 202 | inline bool operator < (const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s, |
| 203 | const sub_match<RandomAccessIterator>& m) |
| 204 | { return s.compare(m.str()) < 0; } |
| 205 | template <class RandomAccessIterator, class traits, class Allocator> |
| 206 | inline bool operator <= (const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s, |
| 207 | const sub_match<RandomAccessIterator>& m) |
| 208 | { return s.compare(m.str()) <= 0; } |
| 209 | template <class RandomAccessIterator, class traits, class Allocator> |
| 210 | inline bool operator >= (const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s, |
| 211 | const sub_match<RandomAccessIterator>& m) |
| 212 | { return s.compare(m.str()) >= 0; } |
| 213 | template <class RandomAccessIterator, class traits, class Allocator> |
| 214 | inline bool operator > (const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s, |
| 215 | const sub_match<RandomAccessIterator>& m) |
| 216 | { return s.compare(m.str()) > 0; } |
| 217 | // comparison to std::basic_string<> part 2: |
| 218 | template <class RandomAccessIterator, class traits, class Allocator> |
| 219 | inline bool operator == (const sub_match<RandomAccessIterator>& m, |
| 220 | const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s) |
| 221 | { return m.str().compare(s) == 0; } |
| 222 | template <class RandomAccessIterator, class traits, class Allocator> |
| 223 | inline bool operator != (const sub_match<RandomAccessIterator>& m, |
| 224 | const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s) |
| 225 | { return m.str().compare(s) != 0; } |
| 226 | template <class RandomAccessIterator, class traits, class Allocator> |
| 227 | inline bool operator < (const sub_match<RandomAccessIterator>& m, |
| 228 | const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s) |
| 229 | { return m.str().compare(s) < 0; } |
| 230 | template <class RandomAccessIterator, class traits, class Allocator> |
| 231 | inline bool operator > (const sub_match<RandomAccessIterator>& m, |
| 232 | const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s) |
| 233 | { return m.str().compare(s) > 0; } |
| 234 | template <class RandomAccessIterator, class traits, class Allocator> |
| 235 | inline bool operator <= (const sub_match<RandomAccessIterator>& m, |
| 236 | const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s) |
| 237 | { return m.str().compare(s) <= 0; } |
| 238 | template <class RandomAccessIterator, class traits, class Allocator> |
| 239 | inline bool operator >= (const sub_match<RandomAccessIterator>& m, |
| 240 | const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s) |
| 241 | { return m.str().compare(s) >= 0; } |
| 242 | // comparison to const charT* part 1: |
| 243 | template <class RandomAccessIterator> |
| 244 | inline bool operator == (const sub_match<RandomAccessIterator>& m, |
| 245 | typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const* s) |
| 246 | { return m.str().compare(s) == 0; } |
| 247 | template <class RandomAccessIterator> |
| 248 | inline bool operator != (const sub_match<RandomAccessIterator>& m, |
| 249 | typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const* s) |
| 250 | { return m.str().compare(s) != 0; } |
| 251 | template <class RandomAccessIterator> |
| 252 | inline bool operator > (const sub_match<RandomAccessIterator>& m, |
| 253 | typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const* s) |
| 254 | { return m.str().compare(s) > 0; } |
| 255 | template <class RandomAccessIterator> |
| 256 | inline bool operator < (const sub_match<RandomAccessIterator>& m, |
| 257 | typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const* s) |
| 258 | { return m.str().compare(s) < 0; } |
| 259 | template <class RandomAccessIterator> |
| 260 | inline bool operator >= (const sub_match<RandomAccessIterator>& m, |
| 261 | typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const* s) |
| 262 | { return m.str().compare(s) >= 0; } |
| 263 | template <class RandomAccessIterator> |
| 264 | inline bool operator <= (const sub_match<RandomAccessIterator>& m, |
| 265 | typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const* s) |
| 266 | { return m.str().compare(s) <= 0; } |
| 267 | // comparison to const charT* part 2: |
| 268 | template <class RandomAccessIterator> |
| 269 | inline bool operator == (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const* s, |
| 270 | const sub_match<RandomAccessIterator>& m) |
| 271 | { return m.str().compare(s) == 0; } |
| 272 | template <class RandomAccessIterator> |
| 273 | inline bool operator != (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const* s, |
| 274 | const sub_match<RandomAccessIterator>& m) |
| 275 | { return m.str().compare(s) != 0; } |
| 276 | template <class RandomAccessIterator> |
| 277 | inline bool operator < (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const* s, |
| 278 | const sub_match<RandomAccessIterator>& m) |
| 279 | { return m.str().compare(s) > 0; } |
| 280 | template <class RandomAccessIterator> |
| 281 | inline bool operator > (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const* s, |
| 282 | const sub_match<RandomAccessIterator>& m) |
| 283 | { return m.str().compare(s) < 0; } |
| 284 | template <class RandomAccessIterator> |
| 285 | inline bool operator <= (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const* s, |
| 286 | const sub_match<RandomAccessIterator>& m) |
| 287 | { return m.str().compare(s) >= 0; } |
| 288 | template <class RandomAccessIterator> |
| 289 | inline bool operator >= (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const* s, |
| 290 | const sub_match<RandomAccessIterator>& m) |
| 291 | { return m.str().compare(s) <= 0; } |
| 292 | |
| 293 | // comparison to const charT& part 1: |
| 294 | template <class RandomAccessIterator> |
| 295 | inline bool operator == (const sub_match<RandomAccessIterator>& m, |
| 296 | typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s) |
| 297 | { return m.str().compare(0, m.length(), &s, 1) == 0; } |
| 298 | template <class RandomAccessIterator> |
| 299 | inline bool operator != (const sub_match<RandomAccessIterator>& m, |
| 300 | typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s) |
| 301 | { return m.str().compare(0, m.length(), &s, 1) != 0; } |
| 302 | template <class RandomAccessIterator> |
| 303 | inline bool operator > (const sub_match<RandomAccessIterator>& m, |
| 304 | typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s) |
| 305 | { return m.str().compare(0, m.length(), &s, 1) > 0; } |
| 306 | template <class RandomAccessIterator> |
| 307 | inline bool operator < (const sub_match<RandomAccessIterator>& m, |
| 308 | typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s) |
| 309 | { return m.str().compare(0, m.length(), &s, 1) < 0; } |
| 310 | template <class RandomAccessIterator> |
| 311 | inline bool operator >= (const sub_match<RandomAccessIterator>& m, |
| 312 | typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s) |
| 313 | { return m.str().compare(0, m.length(), &s, 1) >= 0; } |
| 314 | template <class RandomAccessIterator> |
| 315 | inline bool operator <= (const sub_match<RandomAccessIterator>& m, |
| 316 | typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s) |
| 317 | { return m.str().compare(0, m.length(), &s, 1) <= 0; } |
| 318 | // comparison to const charT* part 2: |
| 319 | template <class RandomAccessIterator> |
| 320 | inline bool operator == (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s, |
| 321 | const sub_match<RandomAccessIterator>& m) |
| 322 | { return m.str().compare(0, m.length(), &s, 1) == 0; } |
| 323 | template <class RandomAccessIterator> |
| 324 | inline bool operator != (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s, |
| 325 | const sub_match<RandomAccessIterator>& m) |
| 326 | { return m.str().compare(0, m.length(), &s, 1) != 0; } |
| 327 | template <class RandomAccessIterator> |
| 328 | inline bool operator < (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s, |
| 329 | const sub_match<RandomAccessIterator>& m) |
| 330 | { return m.str().compare(0, m.length(), &s, 1) > 0; } |
| 331 | template <class RandomAccessIterator> |
| 332 | inline bool operator > (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s, |
| 333 | const sub_match<RandomAccessIterator>& m) |
| 334 | { return m.str().compare(0, m.length(), &s, 1) < 0; } |
| 335 | template <class RandomAccessIterator> |
| 336 | inline bool operator <= (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s, |
| 337 | const sub_match<RandomAccessIterator>& m) |
| 338 | { return m.str().compare(0, m.length(), &s, 1) >= 0; } |
| 339 | template <class RandomAccessIterator> |
| 340 | inline bool operator >= (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s, |
| 341 | const sub_match<RandomAccessIterator>& m) |
| 342 | { return m.str().compare(0, m.length(), &s, 1) <= 0; } |
| 343 | |
| 344 | // addition operators: |
| 345 | template <class RandomAccessIterator, class traits, class Allocator> |
| 346 | inline std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator> |
| 347 | operator + (const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s, |
| 348 | const sub_match<RandomAccessIterator>& m) |
| 349 | { |
| 350 | std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator> result; |
| 351 | result.reserve(s.size() + m.length() + 1); |
| 352 | return result.append(s).append(m.first, m.second); |
| 353 | } |
| 354 | template <class RandomAccessIterator, class traits, class Allocator> |
| 355 | inline std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator> |
| 356 | operator + (const sub_match<RandomAccessIterator>& m, |
| 357 | const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s) |
| 358 | { |
| 359 | std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator> result; |
| 360 | result.reserve(s.size() + m.length() + 1); |
| 361 | return result.append(m.first, m.second).append(s); |
| 362 | } |
| 363 | #if !(defined(__GNUC__) && defined(NDNBOOST_NO_STD_LOCALE)) |
| 364 | template <class RandomAccessIterator> |
| 365 | inline std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type> |
| 366 | operator + (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const* s, |
| 367 | const sub_match<RandomAccessIterator>& m) |
| 368 | { |
| 369 | std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type> result; |
| 370 | result.reserve(std::char_traits<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type>::length(s) + m.length() + 1); |
| 371 | return result.append(s).append(m.first, m.second); |
| 372 | } |
| 373 | template <class RandomAccessIterator> |
| 374 | inline std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type> |
| 375 | operator + (const sub_match<RandomAccessIterator>& m, |
| 376 | typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const * s) |
| 377 | { |
| 378 | std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type> result; |
| 379 | result.reserve(std::char_traits<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type>::length(s) + m.length() + 1); |
| 380 | return result.append(m.first, m.second).append(s); |
| 381 | } |
| 382 | #else |
| 383 | // worwaround versions: |
| 384 | template <class RandomAccessIterator> |
| 385 | inline std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type> |
| 386 | operator + (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const* s, |
| 387 | const sub_match<RandomAccessIterator>& m) |
| 388 | { |
| 389 | return s + m.str(); |
| 390 | } |
| 391 | template <class RandomAccessIterator> |
| 392 | inline std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type> |
| 393 | operator + (const sub_match<RandomAccessIterator>& m, |
| 394 | typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const * s) |
| 395 | { |
| 396 | return m.str() + s; |
| 397 | } |
| 398 | #endif |
| 399 | template <class RandomAccessIterator> |
| 400 | inline std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type> |
| 401 | operator + (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s, |
| 402 | const sub_match<RandomAccessIterator>& m) |
| 403 | { |
| 404 | std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type> result; |
| 405 | result.reserve(m.length() + 2); |
| 406 | return result.append(1, s).append(m.first, m.second); |
| 407 | } |
| 408 | template <class RandomAccessIterator> |
| 409 | inline std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type> |
| 410 | operator + (const sub_match<RandomAccessIterator>& m, |
| 411 | typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s) |
| 412 | { |
| 413 | std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type> result; |
| 414 | result.reserve(m.length() + 2); |
| 415 | return result.append(m.first, m.second).append(1, s); |
| 416 | } |
| 417 | template <class RandomAccessIterator> |
| 418 | inline std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type> |
| 419 | operator + (const sub_match<RandomAccessIterator>& m1, |
| 420 | const sub_match<RandomAccessIterator>& m2) |
| 421 | { |
| 422 | std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type> result; |
| 423 | result.reserve(m1.length() + m2.length() + 1); |
| 424 | return result.append(m1.first, m1.second).append(m2.first, m2.second); |
| 425 | } |
| 426 | #ifndef NDNBOOST_NO_STD_LOCALE |
| 427 | template <class charT, class traits, class RandomAccessIterator> |
| 428 | std::basic_ostream<charT, traits>& |
| 429 | operator << (std::basic_ostream<charT, traits>& os, |
| 430 | const sub_match<RandomAccessIterator>& s) |
| 431 | { |
| 432 | return (os << s.str()); |
| 433 | } |
| 434 | #else |
| 435 | template <class RandomAccessIterator> |
| 436 | std::ostream& operator << (std::ostream& os, |
| 437 | const sub_match<RandomAccessIterator>& s) |
| 438 | { |
| 439 | return (os << s.str()); |
| 440 | } |
| 441 | #endif |
| 442 | |
| 443 | #ifdef NDNBOOST_OLD_REGEX_H |
| 444 | namespace re_detail{ |
| 445 | template <class BidiIterator, class charT> |
| 446 | int do_toi(BidiIterator i, BidiIterator j, char c, int radix) |
| 447 | { |
| 448 | std::string s(i, j); |
| 449 | char* p; |
| 450 | int result = std::strtol(s.c_str(), &p, radix); |
| 451 | if(*p)raise_regex_exception("Bad sub-expression"); |
| 452 | return result; |
| 453 | } |
| 454 | |
| 455 | // |
| 456 | // helper: |
| 457 | template <class I, class charT> |
| 458 | int do_toi(I& i, I j, charT c) |
| 459 | { |
| 460 | int result = 0; |
| 461 | while((i != j) && (isdigit(*i))) |
| 462 | { |
| 463 | result = result*10 + (*i - '0'); |
| 464 | ++i; |
| 465 | } |
| 466 | return result; |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | |
| 471 | template <class BidiIterator> |
| 472 | sub_match<BidiIterator>::operator int()const |
| 473 | { |
| 474 | BidiIterator i = first; |
| 475 | BidiIterator j = second; |
| 476 | if(i == j)raise_regex_exception("Bad sub-expression"); |
| 477 | int neg = 1; |
| 478 | if((i != j) && (*i == '-')) |
| 479 | { |
| 480 | neg = -1; |
| 481 | ++i; |
| 482 | } |
| 483 | neg *= re_detail::do_toi(i, j, *i); |
| 484 | if(i != j)raise_regex_exception("Bad sub-expression"); |
| 485 | return neg; |
| 486 | } |
| 487 | template <class BidiIterator> |
| 488 | sub_match<BidiIterator>::operator unsigned int()const |
| 489 | { |
| 490 | BidiIterator i = first; |
| 491 | BidiIterator j = second; |
| 492 | if(i == j) |
| 493 | raise_regex_exception("Bad sub-expression"); |
| 494 | return re_detail::do_toi(i, j, *first); |
| 495 | } |
| 496 | #endif |
| 497 | |
| 498 | } // namespace ndnboost |
| 499 | |
| 500 | #ifdef NDNBOOST_MSVC |
| 501 | #pragma warning(push) |
| 502 | #pragma warning(disable: 4103) |
| 503 | #endif |
| 504 | #ifdef NDNBOOST_HAS_ABI_HEADERS |
| 505 | # include NDNBOOST_ABI_SUFFIX |
| 506 | #endif |
| 507 | #ifdef NDNBOOST_MSVC |
| 508 | #pragma warning(pop) |
| 509 | #endif |
| 510 | |
| 511 | #endif |
| 512 | |