sub_match.hpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  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 re_detail::regex_iterator_traits<BidiIterator>::value_type value_type;
  34. #if defined(BOOST_NO_STD_ITERATOR_TRAITS) || defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  35. typedef std::ptrdiff_t difference_type;
  36. #else
  37. typedef typename re_detail::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_MSVC, < 1310)\
  47. && !BOOST_WORKAROUND(__BORLANDC__, <= 0x0551)\
  48. && !BOOST_WORKAROUND(__DECCXX_VER, BOOST_TESTED_AT(60590042))
  49. template <class T, class A>
  50. operator std::basic_string<value_type, T, A> ()const
  51. {
  52. return matched ? std::basic_string<value_type, T, A>(this->first, this->second) : std::basic_string<value_type, T, A>();
  53. }
  54. #else
  55. operator std::basic_string<value_type> ()const
  56. {
  57. return str();
  58. }
  59. #endif
  60. difference_type BOOST_REGEX_CALL length()const
  61. {
  62. difference_type n = matched ? ::boost::re_detail::distance((BidiIterator)this->first, (BidiIterator)this->second) : 0;
  63. return n;
  64. }
  65. std::basic_string<value_type> str()const
  66. {
  67. std::basic_string<value_type> result;
  68. if(matched)
  69. {
  70. std::size_t len = ::boost::re_detail::distance((BidiIterator)this->first, (BidiIterator)this->second);
  71. result.reserve(len);
  72. BidiIterator i = this->first;
  73. while(i != this->second)
  74. {
  75. result.append(1, *i);
  76. ++i;
  77. }
  78. }
  79. return result;
  80. }
  81. int compare(const sub_match& s)const
  82. {
  83. if(matched != s.matched)
  84. return static_cast<int>(matched) - static_cast<int>(s.matched);
  85. return str().compare(s.str());
  86. }
  87. int compare(const std::basic_string<value_type>& s)const
  88. {
  89. return str().compare(s);
  90. }
  91. int compare(const value_type* p)const
  92. {
  93. return str().compare(p);
  94. }
  95. bool operator==(const sub_match& that)const
  96. { return compare(that) == 0; }
  97. bool BOOST_REGEX_CALL operator !=(const sub_match& that)const
  98. { return compare(that) != 0; }
  99. bool operator<(const sub_match& that)const
  100. { return compare(that) < 0; }
  101. bool operator>(const sub_match& that)const
  102. { return compare(that) > 0; }
  103. bool operator<=(const sub_match& that)const
  104. { return compare(that) <= 0; }
  105. bool operator>=(const sub_match& that)const
  106. { return compare(that) >= 0; }
  107. #ifdef BOOST_REGEX_MATCH_EXTRA
  108. typedef std::vector<sub_match<BidiIterator> > capture_sequence_type;
  109. const capture_sequence_type& captures()const
  110. {
  111. if(!m_captures)
  112. m_captures.reset(new capture_sequence_type());
  113. return *m_captures;
  114. }
  115. //
  116. // Private implementation API: DO NOT USE!
  117. //
  118. capture_sequence_type& get_captures()const
  119. {
  120. if(!m_captures)
  121. m_captures.reset(new capture_sequence_type());
  122. return *m_captures;
  123. }
  124. private:
  125. mutable boost::scoped_ptr<capture_sequence_type> m_captures;
  126. public:
  127. #endif
  128. sub_match(const sub_match& that, bool
  129. #ifdef BOOST_REGEX_MATCH_EXTRA
  130. deep_copy
  131. #endif
  132. = true
  133. )
  134. : std::pair<BidiIterator, BidiIterator>(that),
  135. matched(that.matched)
  136. {
  137. #ifdef BOOST_REGEX_MATCH_EXTRA
  138. if(that.m_captures)
  139. if(deep_copy)
  140. m_captures.reset(new capture_sequence_type(*(that.m_captures)));
  141. #endif
  142. }
  143. sub_match& operator=(const sub_match& that)
  144. {
  145. this->first = that.first;
  146. this->second = that.second;
  147. matched = that.matched;
  148. #ifdef BOOST_REGEX_MATCH_EXTRA
  149. if(that.m_captures)
  150. get_captures() = *(that.m_captures);
  151. #endif
  152. return *this;
  153. }
  154. #ifdef BOOST_OLD_REGEX_H
  155. //
  156. // the following are deprecated, do not use!!
  157. //
  158. operator int()const;
  159. operator unsigned int()const;
  160. operator short()const
  161. {
  162. return (short)(int)(*this);
  163. }
  164. operator unsigned short()const
  165. {
  166. return (unsigned short)(unsigned int)(*this);
  167. }
  168. #endif
  169. };
  170. typedef sub_match<const char*> csub_match;
  171. typedef sub_match<std::string::const_iterator> ssub_match;
  172. #ifndef BOOST_NO_WREGEX
  173. typedef sub_match<const wchar_t*> wcsub_match;
  174. typedef sub_match<std::wstring::const_iterator> wssub_match;
  175. #endif
  176. // comparison to std::basic_string<> part 1:
  177. template <class RandomAccessIterator, class traits, class Allocator>
  178. inline bool operator == (const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s,
  179. const sub_match<RandomAccessIterator>& m)
  180. { return s.compare(m.str()) == 0; }
  181. template <class RandomAccessIterator, class traits, class Allocator>
  182. inline bool operator != (const std::basic_string<typename re_detail::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 re_detail::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 re_detail::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 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. // comparison to std::basic_string<> part 2:
  202. template <class RandomAccessIterator, class traits, class Allocator>
  203. inline bool operator == (const sub_match<RandomAccessIterator>& m,
  204. const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s)
  205. { return m.str().compare(s) == 0; }
  206. template <class RandomAccessIterator, class traits, class Allocator>
  207. inline bool operator != (const sub_match<RandomAccessIterator>& m,
  208. const std::basic_string<typename re_detail::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 re_detail::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 re_detail::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 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. // comparison to const charT* part 1:
  227. template <class RandomAccessIterator>
  228. inline bool operator == (const sub_match<RandomAccessIterator>& m,
  229. typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const* s)
  230. { return m.str().compare(s) == 0; }
  231. template <class RandomAccessIterator>
  232. inline bool operator != (const sub_match<RandomAccessIterator>& m,
  233. typename re_detail::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 re_detail::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 re_detail::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 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. // comparison to const charT* part 2:
  252. template <class RandomAccessIterator>
  253. inline bool operator == (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const* s,
  254. const sub_match<RandomAccessIterator>& m)
  255. { return m.str().compare(s) == 0; }
  256. template <class RandomAccessIterator>
  257. inline bool operator != (typename re_detail::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 re_detail::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 re_detail::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 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. // comparison to const charT& part 1:
  277. template <class RandomAccessIterator>
  278. inline bool operator == (const sub_match<RandomAccessIterator>& m,
  279. typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s)
  280. { return m.str().compare(0, m.length(), &s, 1) == 0; }
  281. template <class RandomAccessIterator>
  282. inline bool operator != (const sub_match<RandomAccessIterator>& m,
  283. typename re_detail::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 re_detail::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 re_detail::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 re_detail::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 re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s)
  300. { return m.str().compare(0, m.length(), &s, 1) <= 0; }
  301. // comparison to const charT* part 2:
  302. template <class RandomAccessIterator>
  303. inline bool operator == (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s,
  304. const sub_match<RandomAccessIterator>& m)
  305. { return m.str().compare(0, m.length(), &s, 1) == 0; }
  306. template <class RandomAccessIterator>
  307. inline bool operator != (typename re_detail::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 re_detail::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 re_detail::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 re_detail::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 re_detail::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. // addition operators:
  327. template <class RandomAccessIterator, class traits, class Allocator>
  328. inline std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>
  329. operator + (const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s,
  330. const sub_match<RandomAccessIterator>& m)
  331. {
  332. std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator> result;
  333. result.reserve(s.size() + m.length() + 1);
  334. return result.append(s).append(m.first, m.second);
  335. }
  336. template <class RandomAccessIterator, class traits, class Allocator>
  337. inline std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>
  338. operator + (const sub_match<RandomAccessIterator>& m,
  339. const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s)
  340. {
  341. std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator> result;
  342. result.reserve(s.size() + m.length() + 1);
  343. return result.append(m.first, m.second).append(s);
  344. }
  345. #if !(defined(__GNUC__) && defined(BOOST_NO_STD_LOCALE))
  346. template <class RandomAccessIterator>
  347. inline std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type>
  348. operator + (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const* s,
  349. const sub_match<RandomAccessIterator>& m)
  350. {
  351. std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type> result;
  352. result.reserve(std::char_traits<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type>::length(s) + m.length() + 1);
  353. return result.append(s).append(m.first, m.second);
  354. }
  355. template <class RandomAccessIterator>
  356. inline std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type>
  357. operator + (const sub_match<RandomAccessIterator>& m,
  358. typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const * s)
  359. {
  360. std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type> result;
  361. result.reserve(std::char_traits<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type>::length(s) + m.length() + 1);
  362. return result.append(m.first, m.second).append(s);
  363. }
  364. #else
  365. // worwaround versions:
  366. template <class RandomAccessIterator>
  367. inline std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type>
  368. operator + (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const* s,
  369. const sub_match<RandomAccessIterator>& m)
  370. {
  371. return s + m.str();
  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. return m.str() + s;
  379. }
  380. #endif
  381. template <class RandomAccessIterator>
  382. inline std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type>
  383. operator + (typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s,
  384. const sub_match<RandomAccessIterator>& m)
  385. {
  386. std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type> result;
  387. result.reserve(m.length() + 2);
  388. return result.append(1, s).append(m.first, m.second);
  389. }
  390. template <class RandomAccessIterator>
  391. inline std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type>
  392. operator + (const sub_match<RandomAccessIterator>& m,
  393. typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type const& s)
  394. {
  395. std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type> result;
  396. result.reserve(m.length() + 2);
  397. return result.append(m.first, m.second).append(1, s);
  398. }
  399. template <class RandomAccessIterator>
  400. inline std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type>
  401. operator + (const sub_match<RandomAccessIterator>& m1,
  402. const sub_match<RandomAccessIterator>& m2)
  403. {
  404. std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type> result;
  405. result.reserve(m1.length() + m2.length() + 1);
  406. return result.append(m1.first, m1.second).append(m2.first, m2.second);
  407. }
  408. #ifndef BOOST_NO_STD_LOCALE
  409. template <class charT, class traits, class RandomAccessIterator>
  410. std::basic_ostream<charT, traits>&
  411. operator << (std::basic_ostream<charT, traits>& os,
  412. const sub_match<RandomAccessIterator>& s)
  413. {
  414. return (os << s.str());
  415. }
  416. #else
  417. template <class RandomAccessIterator>
  418. std::ostream& operator << (std::ostream& os,
  419. const sub_match<RandomAccessIterator>& s)
  420. {
  421. return (os << s.str());
  422. }
  423. #endif
  424. #ifdef BOOST_OLD_REGEX_H
  425. namespace re_detail{
  426. template <class BidiIterator, class charT>
  427. int do_toi(BidiIterator i, BidiIterator j, char c, int radix)
  428. {
  429. std::string s(i, j);
  430. char* p;
  431. int result = std::strtol(s.c_str(), &p, radix);
  432. if(*p)raise_regex_exception("Bad sub-expression");
  433. return result;
  434. }
  435. //
  436. // helper:
  437. template <class I, class charT>
  438. int do_toi(I& i, I j, charT c)
  439. {
  440. int result = 0;
  441. while((i != j) && (isdigit(*i)))
  442. {
  443. result = result*10 + (*i - '0');
  444. ++i;
  445. }
  446. return result;
  447. }
  448. }
  449. template <class BidiIterator>
  450. sub_match<BidiIterator>::operator int()const
  451. {
  452. BidiIterator i = first;
  453. BidiIterator j = second;
  454. if(i == j)raise_regex_exception("Bad sub-expression");
  455. int neg = 1;
  456. if((i != j) && (*i == '-'))
  457. {
  458. neg = -1;
  459. ++i;
  460. }
  461. neg *= re_detail::do_toi(i, j, *i);
  462. if(i != j)raise_regex_exception("Bad sub-expression");
  463. return neg;
  464. }
  465. template <class BidiIterator>
  466. sub_match<BidiIterator>::operator unsigned int()const
  467. {
  468. BidiIterator i = first;
  469. BidiIterator j = second;
  470. if(i == j)
  471. raise_regex_exception("Bad sub-expression");
  472. return re_detail::do_toi(i, j, *first);
  473. }
  474. #endif
  475. } // namespace boost
  476. #ifdef BOOST_MSVC
  477. #pragma warning(push)
  478. #pragma warning(disable: 4103)
  479. #endif
  480. #ifdef BOOST_HAS_ABI_HEADERS
  481. # include BOOST_ABI_SUFFIX
  482. #endif
  483. #ifdef BOOST_MSVC
  484. #pragma warning(pop)
  485. #endif
  486. #endif