sub_match.hpp 23 KB

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