Jeff Thompson | 86b6d64 | 2013-10-17 15:01:56 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * |
| 3 | * Copyright (c) 1998-2004 John Maddock |
| 4 | * Copyright 2011 Garmin Ltd. or its subsidiaries |
| 5 | * |
| 6 | * Distributed under the Boost Software License, Version 1.0. |
| 7 | * (See accompanying file LICENSE_1_0.txt or copy at |
| 8 | * 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 basic_regex.cpp |
| 15 | * VERSION see <ndnboost/version.hpp> |
| 16 | * DESCRIPTION: Declares template class basic_regex. |
| 17 | */ |
| 18 | |
| 19 | #ifndef NDNBOOST_REGEX_V4_BASIC_REGEX_HPP |
| 20 | #define NDNBOOST_REGEX_V4_BASIC_REGEX_HPP |
| 21 | |
| 22 | #include <ndnboost/type_traits/is_same.hpp> |
| 23 | #include <ndnboost/functional/hash.hpp> |
| 24 | |
| 25 | #ifdef NDNBOOST_MSVC |
| 26 | #pragma warning(push) |
| 27 | #pragma warning(disable: 4103) |
| 28 | #endif |
| 29 | #ifdef NDNBOOST_HAS_ABI_HEADERS |
| 30 | # include NDNBOOST_ABI_PREFIX |
| 31 | #endif |
| 32 | #ifdef NDNBOOST_MSVC |
| 33 | #pragma warning(pop) |
| 34 | #endif |
| 35 | |
| 36 | namespace ndnboost{ |
| 37 | #ifdef NDNBOOST_MSVC |
| 38 | #pragma warning(push) |
| 39 | #pragma warning(disable : 4251 4231 4800) |
| 40 | #if NDNBOOST_MSVC < 1600 |
| 41 | #pragma warning(disable : 4660) |
| 42 | #endif |
| 43 | #endif |
| 44 | |
| 45 | namespace re_detail{ |
| 46 | |
| 47 | // |
| 48 | // forward declaration, we will need this one later: |
| 49 | // |
| 50 | template <class charT, class traits> |
| 51 | class basic_regex_parser; |
| 52 | |
| 53 | template <class I> |
| 54 | void bubble_down_one(I first, I last) |
| 55 | { |
| 56 | if(first != last) |
| 57 | { |
| 58 | I next = last - 1; |
| 59 | while((next != first) && (*next < *(next-1))) |
| 60 | { |
| 61 | (next-1)->swap(*next); |
| 62 | --next; |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | template <class Iterator> |
| 68 | inline int hash_value_from_capture_name(Iterator i, Iterator j) |
| 69 | { |
| 70 | std::size_t r = ndnboost::hash_range(i, j); |
| 71 | r %= ((std::numeric_limits<int>::max)() - 10001); |
| 72 | r += 10000; |
| 73 | return static_cast<int>(r); |
| 74 | } |
| 75 | |
| 76 | class named_subexpressions |
| 77 | { |
| 78 | public: |
| 79 | struct name |
| 80 | { |
| 81 | template <class charT> |
| 82 | name(const charT* i, const charT* j, int idx) |
| 83 | : index(idx) |
| 84 | { |
| 85 | hash = hash_value_from_capture_name(i, j); |
| 86 | } |
| 87 | name(int h, int idx) |
| 88 | : index(idx), hash(h) |
| 89 | { |
| 90 | } |
| 91 | int index; |
| 92 | int hash; |
| 93 | bool operator < (const name& other)const |
| 94 | { |
| 95 | return hash < other.hash; |
| 96 | } |
| 97 | bool operator == (const name& other)const |
| 98 | { |
| 99 | return hash == other.hash; |
| 100 | } |
| 101 | void swap(name& other) |
| 102 | { |
| 103 | std::swap(index, other.index); |
| 104 | std::swap(hash, other.hash); |
| 105 | } |
| 106 | }; |
| 107 | |
| 108 | typedef std::vector<name>::const_iterator const_iterator; |
| 109 | typedef std::pair<const_iterator, const_iterator> range_type; |
| 110 | |
| 111 | named_subexpressions(){} |
| 112 | |
| 113 | template <class charT> |
| 114 | void set_name(const charT* i, const charT* j, int index) |
| 115 | { |
| 116 | m_sub_names.push_back(name(i, j, index)); |
| 117 | bubble_down_one(m_sub_names.begin(), m_sub_names.end()); |
| 118 | } |
| 119 | template <class charT> |
| 120 | int get_id(const charT* i, const charT* j)const |
| 121 | { |
| 122 | name t(i, j, 0); |
| 123 | typename std::vector<name>::const_iterator pos = std::lower_bound(m_sub_names.begin(), m_sub_names.end(), t); |
| 124 | if((pos != m_sub_names.end()) && (*pos == t)) |
| 125 | { |
| 126 | return pos->index; |
| 127 | } |
| 128 | return -1; |
| 129 | } |
| 130 | template <class charT> |
| 131 | range_type equal_range(const charT* i, const charT* j)const |
| 132 | { |
| 133 | name t(i, j, 0); |
| 134 | return std::equal_range(m_sub_names.begin(), m_sub_names.end(), t); |
| 135 | } |
| 136 | int get_id(int h)const |
| 137 | { |
| 138 | name t(h, 0); |
| 139 | std::vector<name>::const_iterator pos = std::lower_bound(m_sub_names.begin(), m_sub_names.end(), t); |
| 140 | if((pos != m_sub_names.end()) && (*pos == t)) |
| 141 | { |
| 142 | return pos->index; |
| 143 | } |
| 144 | return -1; |
| 145 | } |
| 146 | range_type equal_range(int h)const |
| 147 | { |
| 148 | name t(h, 0); |
| 149 | return std::equal_range(m_sub_names.begin(), m_sub_names.end(), t); |
| 150 | } |
| 151 | private: |
| 152 | std::vector<name> m_sub_names; |
| 153 | }; |
| 154 | |
| 155 | // |
| 156 | // class regex_data: |
| 157 | // represents the data we wish to expose to the matching algorithms. |
| 158 | // |
| 159 | template <class charT, class traits> |
| 160 | struct regex_data : public named_subexpressions |
| 161 | { |
| 162 | typedef regex_constants::syntax_option_type flag_type; |
| 163 | typedef std::size_t size_type; |
| 164 | |
| 165 | regex_data(const ::ndnboost::shared_ptr< |
| 166 | ::ndnboost::regex_traits_wrapper<traits> >& t) |
| 167 | : m_ptraits(t), m_expression(0), m_expression_len(0) {} |
| 168 | regex_data() |
| 169 | : m_ptraits(new ::ndnboost::regex_traits_wrapper<traits>()), m_expression(0), m_expression_len(0) {} |
| 170 | |
| 171 | ::ndnboost::shared_ptr< |
| 172 | ::ndnboost::regex_traits_wrapper<traits> |
| 173 | > m_ptraits; // traits class instance |
| 174 | flag_type m_flags; // flags with which we were compiled |
| 175 | int m_status; // error code (0 implies OK). |
| 176 | const charT* m_expression; // the original expression |
| 177 | std::ptrdiff_t m_expression_len; // the length of the original expression |
| 178 | size_type m_mark_count; // the number of marked sub-expressions |
| 179 | re_detail::re_syntax_base* m_first_state; // the first state of the machine |
| 180 | unsigned m_restart_type; // search optimisation type |
| 181 | unsigned char m_startmap[1 << CHAR_BIT]; // which characters can start a match |
| 182 | unsigned int m_can_be_null; // whether we can match a null string |
| 183 | re_detail::raw_storage m_data; // the buffer in which our states are constructed |
| 184 | typename traits::char_class_type m_word_mask; // mask used to determine if a character is a word character |
| 185 | std::vector< |
| 186 | std::pair< |
| 187 | std::size_t, std::size_t> > m_subs; // Position of sub-expressions within the *string*. |
| 188 | bool m_has_recursions; // whether we have recursive expressions; |
| 189 | }; |
| 190 | // |
| 191 | // class basic_regex_implementation |
| 192 | // pimpl implementation class for basic_regex. |
| 193 | // |
| 194 | template <class charT, class traits> |
| 195 | class basic_regex_implementation |
| 196 | : public regex_data<charT, traits> |
| 197 | { |
| 198 | public: |
| 199 | typedef regex_constants::syntax_option_type flag_type; |
| 200 | typedef std::ptrdiff_t difference_type; |
| 201 | typedef std::size_t size_type; |
| 202 | typedef typename traits::locale_type locale_type; |
| 203 | typedef const charT* const_iterator; |
| 204 | |
| 205 | basic_regex_implementation(){} |
| 206 | basic_regex_implementation(const ::ndnboost::shared_ptr< |
| 207 | ::ndnboost::regex_traits_wrapper<traits> >& t) |
| 208 | : regex_data<charT, traits>(t) {} |
| 209 | void assign(const charT* arg_first, |
| 210 | const charT* arg_last, |
| 211 | flag_type f) |
| 212 | { |
| 213 | regex_data<charT, traits>* pdat = this; |
| 214 | basic_regex_parser<charT, traits> parser(pdat); |
| 215 | parser.parse(arg_first, arg_last, f); |
| 216 | } |
| 217 | |
| 218 | locale_type NDNBOOST_REGEX_CALL imbue(locale_type l) |
| 219 | { |
| 220 | return this->m_ptraits->imbue(l); |
| 221 | } |
| 222 | locale_type NDNBOOST_REGEX_CALL getloc()const |
| 223 | { |
| 224 | return this->m_ptraits->getloc(); |
| 225 | } |
| 226 | std::basic_string<charT> NDNBOOST_REGEX_CALL str()const |
| 227 | { |
| 228 | std::basic_string<charT> result; |
| 229 | if(this->m_status == 0) |
| 230 | result = std::basic_string<charT>(this->m_expression, this->m_expression_len); |
| 231 | return result; |
| 232 | } |
| 233 | const_iterator NDNBOOST_REGEX_CALL expression()const |
| 234 | { |
| 235 | return this->m_expression; |
| 236 | } |
| 237 | std::pair<const_iterator, const_iterator> NDNBOOST_REGEX_CALL subexpression(std::size_t n)const |
| 238 | { |
| 239 | if(n == 0) |
| 240 | ndnboost::throw_exception(std::out_of_range("0 is not a valid subexpression index.")); |
| 241 | const std::pair<std::size_t, std::size_t>& pi = this->m_subs.at(n - 1); |
| 242 | std::pair<const_iterator, const_iterator> p(expression() + pi.first, expression() + pi.second); |
| 243 | return p; |
| 244 | } |
| 245 | // |
| 246 | // begin, end: |
| 247 | const_iterator NDNBOOST_REGEX_CALL begin()const |
| 248 | { |
| 249 | return (this->m_status ? 0 : this->m_expression); |
| 250 | } |
| 251 | const_iterator NDNBOOST_REGEX_CALL end()const |
| 252 | { |
| 253 | return (this->m_status ? 0 : this->m_expression + this->m_expression_len); |
| 254 | } |
| 255 | flag_type NDNBOOST_REGEX_CALL flags()const |
| 256 | { |
| 257 | return this->m_flags; |
| 258 | } |
| 259 | size_type NDNBOOST_REGEX_CALL size()const |
| 260 | { |
| 261 | return this->m_expression_len; |
| 262 | } |
| 263 | int NDNBOOST_REGEX_CALL status()const |
| 264 | { |
| 265 | return this->m_status; |
| 266 | } |
| 267 | size_type NDNBOOST_REGEX_CALL mark_count()const |
| 268 | { |
| 269 | return this->m_mark_count; |
| 270 | } |
| 271 | const re_detail::re_syntax_base* get_first_state()const |
| 272 | { |
| 273 | return this->m_first_state; |
| 274 | } |
| 275 | unsigned get_restart_type()const |
| 276 | { |
| 277 | return this->m_restart_type; |
| 278 | } |
| 279 | const unsigned char* get_map()const |
| 280 | { |
| 281 | return this->m_startmap; |
| 282 | } |
| 283 | const ::ndnboost::regex_traits_wrapper<traits>& get_traits()const |
| 284 | { |
| 285 | return *(this->m_ptraits); |
| 286 | } |
| 287 | bool can_be_null()const |
| 288 | { |
| 289 | return this->m_can_be_null; |
| 290 | } |
| 291 | const regex_data<charT, traits>& get_data()const |
| 292 | { |
| 293 | basic_regex_implementation<charT, traits> const* p = this; |
| 294 | return *static_cast<const regex_data<charT, traits>*>(p); |
| 295 | } |
| 296 | }; |
| 297 | |
| 298 | } // namespace re_detail |
| 299 | // |
| 300 | // class basic_regex: |
| 301 | // represents the compiled |
| 302 | // regular expression: |
| 303 | // |
| 304 | |
| 305 | #ifdef NDNBOOST_REGEX_NO_FWD |
| 306 | template <class charT, class traits = regex_traits<charT> > |
| 307 | #else |
| 308 | template <class charT, class traits > |
| 309 | #endif |
| 310 | class basic_regex : public regbase |
| 311 | { |
| 312 | public: |
| 313 | // typedefs: |
| 314 | typedef std::size_t traits_size_type; |
| 315 | typedef typename traits::string_type traits_string_type; |
| 316 | typedef charT char_type; |
| 317 | typedef traits traits_type; |
| 318 | |
| 319 | typedef charT value_type; |
| 320 | typedef charT& reference; |
| 321 | typedef const charT& const_reference; |
| 322 | typedef const charT* const_iterator; |
| 323 | typedef const_iterator iterator; |
| 324 | typedef std::ptrdiff_t difference_type; |
| 325 | typedef std::size_t size_type; |
| 326 | typedef regex_constants::syntax_option_type flag_type; |
| 327 | // locale_type |
| 328 | // placeholder for actual locale type used by the |
| 329 | // traits class to localise *this. |
| 330 | typedef typename traits::locale_type locale_type; |
| 331 | |
| 332 | public: |
| 333 | explicit basic_regex(){} |
| 334 | explicit basic_regex(const charT* p, flag_type f = regex_constants::normal) |
| 335 | { |
| 336 | assign(p, f); |
| 337 | } |
| 338 | basic_regex(const charT* p1, const charT* p2, flag_type f = regex_constants::normal) |
| 339 | { |
| 340 | assign(p1, p2, f); |
| 341 | } |
| 342 | basic_regex(const charT* p, size_type len, flag_type f) |
| 343 | { |
| 344 | assign(p, len, f); |
| 345 | } |
| 346 | basic_regex(const basic_regex& that) |
| 347 | : m_pimpl(that.m_pimpl) {} |
| 348 | ~basic_regex(){} |
| 349 | basic_regex& NDNBOOST_REGEX_CALL operator=(const basic_regex& that) |
| 350 | { |
| 351 | return assign(that); |
| 352 | } |
| 353 | basic_regex& NDNBOOST_REGEX_CALL operator=(const charT* ptr) |
| 354 | { |
| 355 | return assign(ptr); |
| 356 | } |
| 357 | |
| 358 | // |
| 359 | // assign: |
| 360 | basic_regex& assign(const basic_regex& that) |
| 361 | { |
| 362 | m_pimpl = that.m_pimpl; |
| 363 | return *this; |
| 364 | } |
| 365 | basic_regex& assign(const charT* p, flag_type f = regex_constants::normal) |
| 366 | { |
| 367 | return assign(p, p + traits::length(p), f); |
| 368 | } |
| 369 | basic_regex& assign(const charT* p, size_type len, flag_type f) |
| 370 | { |
| 371 | return assign(p, p + len, f); |
| 372 | } |
| 373 | private: |
| 374 | basic_regex& do_assign(const charT* p1, |
| 375 | const charT* p2, |
| 376 | flag_type f); |
| 377 | public: |
| 378 | basic_regex& assign(const charT* p1, |
| 379 | const charT* p2, |
| 380 | flag_type f = regex_constants::normal) |
| 381 | { |
| 382 | return do_assign(p1, p2, f); |
| 383 | } |
| 384 | #if !defined(NDNBOOST_NO_MEMBER_TEMPLATES) |
| 385 | |
| 386 | template <class ST, class SA> |
| 387 | unsigned int NDNBOOST_REGEX_CALL set_expression(const std::basic_string<charT, ST, SA>& p, flag_type f = regex_constants::normal) |
| 388 | { |
| 389 | return set_expression(p.data(), p.data() + p.size(), f); |
| 390 | } |
| 391 | |
| 392 | template <class ST, class SA> |
| 393 | explicit basic_regex(const std::basic_string<charT, ST, SA>& p, flag_type f = regex_constants::normal) |
| 394 | { |
| 395 | assign(p, f); |
| 396 | } |
| 397 | |
| 398 | template <class InputIterator> |
| 399 | basic_regex(InputIterator arg_first, InputIterator arg_last, flag_type f = regex_constants::normal) |
| 400 | { |
| 401 | typedef typename traits::string_type seq_type; |
| 402 | seq_type a(arg_first, arg_last); |
| 403 | if(a.size()) |
| 404 | assign(static_cast<const charT*>(&*a.begin()), static_cast<const charT*>(&*a.begin() + a.size()), f); |
| 405 | else |
| 406 | assign(static_cast<const charT*>(0), static_cast<const charT*>(0), f); |
| 407 | } |
| 408 | |
| 409 | template <class ST, class SA> |
| 410 | basic_regex& NDNBOOST_REGEX_CALL operator=(const std::basic_string<charT, ST, SA>& p) |
| 411 | { |
| 412 | return assign(p.data(), p.data() + p.size(), regex_constants::normal); |
| 413 | } |
| 414 | |
| 415 | template <class string_traits, class A> |
| 416 | basic_regex& NDNBOOST_REGEX_CALL assign( |
| 417 | const std::basic_string<charT, string_traits, A>& s, |
| 418 | flag_type f = regex_constants::normal) |
| 419 | { |
| 420 | return assign(s.data(), s.data() + s.size(), f); |
| 421 | } |
| 422 | |
| 423 | template <class InputIterator> |
| 424 | basic_regex& NDNBOOST_REGEX_CALL assign(InputIterator arg_first, |
| 425 | InputIterator arg_last, |
| 426 | flag_type f = regex_constants::normal) |
| 427 | { |
| 428 | typedef typename traits::string_type seq_type; |
| 429 | seq_type a(arg_first, arg_last); |
| 430 | if(a.size()) |
| 431 | { |
| 432 | const charT* p1 = &*a.begin(); |
| 433 | const charT* p2 = &*a.begin() + a.size(); |
| 434 | return assign(p1, p2, f); |
| 435 | } |
| 436 | return assign(static_cast<const charT*>(0), static_cast<const charT*>(0), f); |
| 437 | } |
| 438 | #else |
| 439 | unsigned int NDNBOOST_REGEX_CALL set_expression(const std::basic_string<charT>& p, flag_type f = regex_constants::normal) |
| 440 | { |
| 441 | return set_expression(p.data(), p.data() + p.size(), f); |
| 442 | } |
| 443 | |
| 444 | basic_regex(const std::basic_string<charT>& p, flag_type f = regex_constants::normal) |
| 445 | { |
| 446 | assign(p, f); |
| 447 | } |
| 448 | |
| 449 | basic_regex& NDNBOOST_REGEX_CALL operator=(const std::basic_string<charT>& p) |
| 450 | { |
| 451 | return assign(p.data(), p.data() + p.size(), regex_constants::normal); |
| 452 | } |
| 453 | |
| 454 | basic_regex& NDNBOOST_REGEX_CALL assign( |
| 455 | const std::basic_string<charT>& s, |
| 456 | flag_type f = regex_constants::normal) |
| 457 | { |
| 458 | return assign(s.data(), s.data() + s.size(), f); |
| 459 | } |
| 460 | |
| 461 | #endif |
| 462 | |
| 463 | // |
| 464 | // locale: |
| 465 | locale_type NDNBOOST_REGEX_CALL imbue(locale_type l); |
| 466 | locale_type NDNBOOST_REGEX_CALL getloc()const |
| 467 | { |
| 468 | return m_pimpl.get() ? m_pimpl->getloc() : locale_type(); |
| 469 | } |
| 470 | // |
| 471 | // getflags: |
| 472 | // retained for backwards compatibility only, "flags" |
| 473 | // is now the preferred name: |
| 474 | flag_type NDNBOOST_REGEX_CALL getflags()const |
| 475 | { |
| 476 | return flags(); |
| 477 | } |
| 478 | flag_type NDNBOOST_REGEX_CALL flags()const |
| 479 | { |
| 480 | return m_pimpl.get() ? m_pimpl->flags() : 0; |
| 481 | } |
| 482 | // |
| 483 | // str: |
| 484 | std::basic_string<charT> NDNBOOST_REGEX_CALL str()const |
| 485 | { |
| 486 | return m_pimpl.get() ? m_pimpl->str() : std::basic_string<charT>(); |
| 487 | } |
| 488 | // |
| 489 | // begin, end, subexpression: |
| 490 | std::pair<const_iterator, const_iterator> NDNBOOST_REGEX_CALL subexpression(std::size_t n)const |
| 491 | { |
| 492 | if(!m_pimpl.get()) |
| 493 | ndnboost::throw_exception(std::logic_error("Can't access subexpressions in an invalid regex.")); |
| 494 | return m_pimpl->subexpression(n); |
| 495 | } |
| 496 | const_iterator NDNBOOST_REGEX_CALL begin()const |
| 497 | { |
| 498 | return (m_pimpl.get() ? m_pimpl->begin() : 0); |
| 499 | } |
| 500 | const_iterator NDNBOOST_REGEX_CALL end()const |
| 501 | { |
| 502 | return (m_pimpl.get() ? m_pimpl->end() : 0); |
| 503 | } |
| 504 | // |
| 505 | // swap: |
| 506 | void NDNBOOST_REGEX_CALL swap(basic_regex& that)throw() |
| 507 | { |
| 508 | m_pimpl.swap(that.m_pimpl); |
| 509 | } |
| 510 | // |
| 511 | // size: |
| 512 | size_type NDNBOOST_REGEX_CALL size()const |
| 513 | { |
| 514 | return (m_pimpl.get() ? m_pimpl->size() : 0); |
| 515 | } |
| 516 | // |
| 517 | // max_size: |
| 518 | size_type NDNBOOST_REGEX_CALL max_size()const |
| 519 | { |
| 520 | return UINT_MAX; |
| 521 | } |
| 522 | // |
| 523 | // empty: |
| 524 | bool NDNBOOST_REGEX_CALL empty()const |
| 525 | { |
| 526 | return (m_pimpl.get() ? 0 != m_pimpl->status() : true); |
| 527 | } |
| 528 | |
| 529 | size_type NDNBOOST_REGEX_CALL mark_count()const |
| 530 | { |
| 531 | return (m_pimpl.get() ? m_pimpl->mark_count() : 0); |
| 532 | } |
| 533 | |
| 534 | int status()const |
| 535 | { |
| 536 | return (m_pimpl.get() ? m_pimpl->status() : regex_constants::error_empty); |
| 537 | } |
| 538 | |
| 539 | int NDNBOOST_REGEX_CALL compare(const basic_regex& that) const |
| 540 | { |
| 541 | if(m_pimpl.get() == that.m_pimpl.get()) |
| 542 | return 0; |
| 543 | if(!m_pimpl.get()) |
| 544 | return -1; |
| 545 | if(!that.m_pimpl.get()) |
| 546 | return 1; |
| 547 | if(status() != that.status()) |
| 548 | return status() - that.status(); |
| 549 | if(flags() != that.flags()) |
| 550 | return flags() - that.flags(); |
| 551 | return str().compare(that.str()); |
| 552 | } |
| 553 | bool NDNBOOST_REGEX_CALL operator==(const basic_regex& e)const |
| 554 | { |
| 555 | return compare(e) == 0; |
| 556 | } |
| 557 | bool NDNBOOST_REGEX_CALL operator != (const basic_regex& e)const |
| 558 | { |
| 559 | return compare(e) != 0; |
| 560 | } |
| 561 | bool NDNBOOST_REGEX_CALL operator<(const basic_regex& e)const |
| 562 | { |
| 563 | return compare(e) < 0; |
| 564 | } |
| 565 | bool NDNBOOST_REGEX_CALL operator>(const basic_regex& e)const |
| 566 | { |
| 567 | return compare(e) > 0; |
| 568 | } |
| 569 | bool NDNBOOST_REGEX_CALL operator<=(const basic_regex& e)const |
| 570 | { |
| 571 | return compare(e) <= 0; |
| 572 | } |
| 573 | bool NDNBOOST_REGEX_CALL operator>=(const basic_regex& e)const |
| 574 | { |
| 575 | return compare(e) >= 0; |
| 576 | } |
| 577 | |
| 578 | // |
| 579 | // The following are deprecated as public interfaces |
| 580 | // but are available for compatibility with earlier versions. |
| 581 | const charT* NDNBOOST_REGEX_CALL expression()const |
| 582 | { |
| 583 | return (m_pimpl.get() && !m_pimpl->status() ? m_pimpl->expression() : 0); |
| 584 | } |
| 585 | unsigned int NDNBOOST_REGEX_CALL set_expression(const charT* p1, const charT* p2, flag_type f = regex_constants::normal) |
| 586 | { |
| 587 | assign(p1, p2, f | regex_constants::no_except); |
| 588 | return status(); |
| 589 | } |
| 590 | unsigned int NDNBOOST_REGEX_CALL set_expression(const charT* p, flag_type f = regex_constants::normal) |
| 591 | { |
| 592 | assign(p, f | regex_constants::no_except); |
| 593 | return status(); |
| 594 | } |
| 595 | unsigned int NDNBOOST_REGEX_CALL error_code()const |
| 596 | { |
| 597 | return status(); |
| 598 | } |
| 599 | // |
| 600 | // private access methods: |
| 601 | // |
| 602 | const re_detail::re_syntax_base* get_first_state()const |
| 603 | { |
| 604 | NDNBOOST_ASSERT(0 != m_pimpl.get()); |
| 605 | return m_pimpl->get_first_state(); |
| 606 | } |
| 607 | unsigned get_restart_type()const |
| 608 | { |
| 609 | NDNBOOST_ASSERT(0 != m_pimpl.get()); |
| 610 | return m_pimpl->get_restart_type(); |
| 611 | } |
| 612 | const unsigned char* get_map()const |
| 613 | { |
| 614 | NDNBOOST_ASSERT(0 != m_pimpl.get()); |
| 615 | return m_pimpl->get_map(); |
| 616 | } |
| 617 | const ::ndnboost::regex_traits_wrapper<traits>& get_traits()const |
| 618 | { |
| 619 | NDNBOOST_ASSERT(0 != m_pimpl.get()); |
| 620 | return m_pimpl->get_traits(); |
| 621 | } |
| 622 | bool can_be_null()const |
| 623 | { |
| 624 | NDNBOOST_ASSERT(0 != m_pimpl.get()); |
| 625 | return m_pimpl->can_be_null(); |
| 626 | } |
| 627 | const re_detail::regex_data<charT, traits>& get_data()const |
| 628 | { |
| 629 | NDNBOOST_ASSERT(0 != m_pimpl.get()); |
| 630 | return m_pimpl->get_data(); |
| 631 | } |
| 632 | ndnboost::shared_ptr<re_detail::named_subexpressions > get_named_subs()const |
| 633 | { |
| 634 | return m_pimpl; |
| 635 | } |
| 636 | |
| 637 | private: |
| 638 | shared_ptr<re_detail::basic_regex_implementation<charT, traits> > m_pimpl; |
| 639 | }; |
| 640 | |
| 641 | // |
| 642 | // out of line members; |
| 643 | // these are the only members that mutate the basic_regex object, |
| 644 | // and are designed to provide the strong exception guarentee |
| 645 | // (in the event of a throw, the state of the object remains unchanged). |
| 646 | // |
| 647 | template <class charT, class traits> |
| 648 | basic_regex<charT, traits>& basic_regex<charT, traits>::do_assign(const charT* p1, |
| 649 | const charT* p2, |
| 650 | flag_type f) |
| 651 | { |
| 652 | shared_ptr<re_detail::basic_regex_implementation<charT, traits> > temp; |
| 653 | if(!m_pimpl.get()) |
| 654 | { |
| 655 | temp = shared_ptr<re_detail::basic_regex_implementation<charT, traits> >(new re_detail::basic_regex_implementation<charT, traits>()); |
| 656 | } |
| 657 | else |
| 658 | { |
| 659 | temp = shared_ptr<re_detail::basic_regex_implementation<charT, traits> >(new re_detail::basic_regex_implementation<charT, traits>(m_pimpl->m_ptraits)); |
| 660 | } |
| 661 | temp->assign(p1, p2, f); |
| 662 | temp.swap(m_pimpl); |
| 663 | return *this; |
| 664 | } |
| 665 | |
| 666 | template <class charT, class traits> |
| 667 | typename basic_regex<charT, traits>::locale_type NDNBOOST_REGEX_CALL basic_regex<charT, traits>::imbue(locale_type l) |
| 668 | { |
| 669 | shared_ptr<re_detail::basic_regex_implementation<charT, traits> > temp(new re_detail::basic_regex_implementation<charT, traits>()); |
| 670 | locale_type result = temp->imbue(l); |
| 671 | temp.swap(m_pimpl); |
| 672 | return result; |
| 673 | } |
| 674 | |
| 675 | // |
| 676 | // non-members: |
| 677 | // |
| 678 | template <class charT, class traits> |
| 679 | void swap(basic_regex<charT, traits>& e1, basic_regex<charT, traits>& e2) |
| 680 | { |
| 681 | e1.swap(e2); |
| 682 | } |
| 683 | |
| 684 | #ifndef NDNBOOST_NO_STD_LOCALE |
| 685 | template <class charT, class traits, class traits2> |
| 686 | std::basic_ostream<charT, traits>& |
| 687 | operator << (std::basic_ostream<charT, traits>& os, |
| 688 | const basic_regex<charT, traits2>& e) |
| 689 | { |
| 690 | return (os << e.str()); |
| 691 | } |
| 692 | #else |
| 693 | template <class traits> |
| 694 | std::ostream& operator << (std::ostream& os, const basic_regex<char, traits>& e) |
| 695 | { |
| 696 | return (os << e.str()); |
| 697 | } |
| 698 | #endif |
| 699 | |
| 700 | // |
| 701 | // class reg_expression: |
| 702 | // this is provided for backwards compatibility only, |
| 703 | // it is deprecated, no not use! |
| 704 | // |
| 705 | #ifdef NDNBOOST_REGEX_NO_FWD |
| 706 | template <class charT, class traits = regex_traits<charT> > |
| 707 | #else |
| 708 | template <class charT, class traits > |
| 709 | #endif |
| 710 | class reg_expression : public basic_regex<charT, traits> |
| 711 | { |
| 712 | public: |
| 713 | typedef typename basic_regex<charT, traits>::flag_type flag_type; |
| 714 | typedef typename basic_regex<charT, traits>::size_type size_type; |
| 715 | explicit reg_expression(){} |
| 716 | explicit reg_expression(const charT* p, flag_type f = regex_constants::normal) |
| 717 | : basic_regex<charT, traits>(p, f){} |
| 718 | reg_expression(const charT* p1, const charT* p2, flag_type f = regex_constants::normal) |
| 719 | : basic_regex<charT, traits>(p1, p2, f){} |
| 720 | reg_expression(const charT* p, size_type len, flag_type f) |
| 721 | : basic_regex<charT, traits>(p, len, f){} |
| 722 | reg_expression(const reg_expression& that) |
| 723 | : basic_regex<charT, traits>(that) {} |
| 724 | ~reg_expression(){} |
| 725 | reg_expression& NDNBOOST_REGEX_CALL operator=(const reg_expression& that) |
| 726 | { |
| 727 | return this->assign(that); |
| 728 | } |
| 729 | |
| 730 | #if !defined(NDNBOOST_NO_MEMBER_TEMPLATES) |
| 731 | template <class ST, class SA> |
| 732 | explicit reg_expression(const std::basic_string<charT, ST, SA>& p, flag_type f = regex_constants::normal) |
| 733 | : basic_regex<charT, traits>(p, f) |
| 734 | { |
| 735 | } |
| 736 | |
| 737 | template <class InputIterator> |
| 738 | reg_expression(InputIterator arg_first, InputIterator arg_last, flag_type f = regex_constants::normal) |
| 739 | : basic_regex<charT, traits>(arg_first, arg_last, f) |
| 740 | { |
| 741 | } |
| 742 | |
| 743 | template <class ST, class SA> |
| 744 | reg_expression& NDNBOOST_REGEX_CALL operator=(const std::basic_string<charT, ST, SA>& p) |
| 745 | { |
| 746 | this->assign(p); |
| 747 | return *this; |
| 748 | } |
| 749 | #else |
| 750 | explicit reg_expression(const std::basic_string<charT>& p, flag_type f = regex_constants::normal) |
| 751 | : basic_regex<charT, traits>(p, f) |
| 752 | { |
| 753 | } |
| 754 | |
| 755 | reg_expression& NDNBOOST_REGEX_CALL operator=(const std::basic_string<charT>& p) |
| 756 | { |
| 757 | this->assign(p); |
| 758 | return *this; |
| 759 | } |
| 760 | #endif |
| 761 | |
| 762 | }; |
| 763 | |
| 764 | #ifdef NDNBOOST_MSVC |
| 765 | #pragma warning (pop) |
| 766 | #endif |
| 767 | |
| 768 | } // namespace ndnboost |
| 769 | |
| 770 | #ifdef NDNBOOST_MSVC |
| 771 | #pragma warning(push) |
| 772 | #pragma warning(disable: 4103) |
| 773 | #endif |
| 774 | #ifdef NDNBOOST_HAS_ABI_HEADERS |
| 775 | # include NDNBOOST_ABI_SUFFIX |
| 776 | #endif |
| 777 | #ifdef NDNBOOST_MSVC |
| 778 | #pragma warning(pop) |
| 779 | #endif |
| 780 | |
| 781 | #endif |
| 782 | |