basic_regex.hpp 21 KB

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