regex_search.hpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 regex_search.hpp
  14. * VERSION see <boost/version.hpp>
  15. * DESCRIPTION: Provides regex_search implementation.
  16. */
  17. #ifndef BOOST_REGEX_V4_REGEX_SEARCH_HPP
  18. #define BOOST_REGEX_V4_REGEX_SEARCH_HPP
  19. namespace boost{
  20. #ifdef BOOST_MSVC
  21. #pragma warning(push)
  22. #pragma warning(disable: 4103)
  23. #endif
  24. #ifdef BOOST_HAS_ABI_HEADERS
  25. # include BOOST_ABI_PREFIX
  26. #endif
  27. #ifdef BOOST_MSVC
  28. #pragma warning(pop)
  29. #endif
  30. template <class BidiIterator, class Allocator, class charT, class traits>
  31. bool regex_search(BidiIterator first, BidiIterator last,
  32. match_results<BidiIterator, Allocator>& m,
  33. const basic_regex<charT, traits>& e,
  34. match_flag_type flags = match_default)
  35. {
  36. return regex_search(first, last, m, e, flags, first);
  37. }
  38. template <class BidiIterator, class Allocator, class charT, class traits>
  39. bool regex_search(BidiIterator first, BidiIterator last,
  40. match_results<BidiIterator, Allocator>& m,
  41. const basic_regex<charT, traits>& e,
  42. match_flag_type flags,
  43. BidiIterator base)
  44. {
  45. if(e.flags() & regex_constants::failbit)
  46. return false;
  47. BOOST_REGEX_DETAIL_NS::perl_matcher<BidiIterator, Allocator, traits> matcher(first, last, m, e, flags, base);
  48. return matcher.find();
  49. }
  50. //
  51. // regex_search convenience interfaces:
  52. #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
  53. //
  54. // this isn't really a partial specialisation, but template function
  55. // overloading - if the compiler doesn't support partial specialisation
  56. // then it really won't support this either:
  57. template <class charT, class Allocator, class traits>
  58. inline bool regex_search(const charT* str,
  59. match_results<const charT*, Allocator>& m,
  60. const basic_regex<charT, traits>& e,
  61. match_flag_type flags = match_default)
  62. {
  63. return regex_search(str, str + traits::length(str), m, e, flags);
  64. }
  65. template <class ST, class SA, class Allocator, class charT, class traits>
  66. inline bool regex_search(const std::basic_string<charT, ST, SA>& s,
  67. match_results<typename std::basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
  68. const basic_regex<charT, traits>& e,
  69. match_flag_type flags = match_default)
  70. {
  71. return regex_search(s.begin(), s.end(), m, e, flags);
  72. }
  73. #else // partial overloads:
  74. inline bool regex_search(const char* str,
  75. cmatch& m,
  76. const regex& e,
  77. match_flag_type flags = match_default)
  78. {
  79. return regex_search(str, str + regex::traits_type::length(str), m, e, flags);
  80. }
  81. inline bool regex_search(const char* first, const char* last,
  82. const regex& e,
  83. match_flag_type flags = match_default)
  84. {
  85. cmatch m;
  86. return regex_search(first, last, m, e, flags | regex_constants::match_any);
  87. }
  88. #ifndef BOOST_NO_WREGEX
  89. inline bool regex_search(const wchar_t* str,
  90. wcmatch& m,
  91. const wregex& e,
  92. match_flag_type flags = match_default)
  93. {
  94. return regex_search(str, str + wregex::traits_type::length(str), m, e, flags);
  95. }
  96. inline bool regex_search(const wchar_t* first, const wchar_t* last,
  97. const wregex& e,
  98. match_flag_type flags = match_default)
  99. {
  100. wcmatch m;
  101. return regex_search(first, last, m, e, flags | regex_constants::match_any);
  102. }
  103. #endif
  104. inline bool regex_search(const std::string& s,
  105. smatch& m,
  106. const regex& e,
  107. match_flag_type flags = match_default)
  108. {
  109. return regex_search(s.begin(), s.end(), m, e, flags);
  110. }
  111. #if !defined(BOOST_NO_WREGEX)
  112. inline bool regex_search(const std::basic_string<wchar_t>& s,
  113. wsmatch& m,
  114. const wregex& e,
  115. match_flag_type flags = match_default)
  116. {
  117. return regex_search(s.begin(), s.end(), m, e, flags);
  118. }
  119. #endif
  120. #endif
  121. template <class BidiIterator, class charT, class traits>
  122. bool regex_search(BidiIterator first, BidiIterator last,
  123. const basic_regex<charT, traits>& e,
  124. match_flag_type flags = match_default)
  125. {
  126. if(e.flags() & regex_constants::failbit)
  127. return false;
  128. match_results<BidiIterator> m;
  129. typedef typename match_results<BidiIterator>::allocator_type match_alloc_type;
  130. BOOST_REGEX_DETAIL_NS::perl_matcher<BidiIterator, match_alloc_type, traits> matcher(first, last, m, e, flags | regex_constants::match_any, first);
  131. return matcher.find();
  132. }
  133. #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
  134. template <class charT, class traits>
  135. inline bool regex_search(const charT* str,
  136. const basic_regex<charT, traits>& e,
  137. match_flag_type flags = match_default)
  138. {
  139. return regex_search(str, str + traits::length(str), e, flags);
  140. }
  141. template <class ST, class SA, class charT, class traits>
  142. inline bool regex_search(const std::basic_string<charT, ST, SA>& s,
  143. const basic_regex<charT, traits>& e,
  144. match_flag_type flags = match_default)
  145. {
  146. return regex_search(s.begin(), s.end(), e, flags);
  147. }
  148. #else // non-template function overloads
  149. inline bool regex_search(const char* str,
  150. const regex& e,
  151. match_flag_type flags = match_default)
  152. {
  153. cmatch m;
  154. return regex_search(str, str + regex::traits_type::length(str), m, e, flags | regex_constants::match_any);
  155. }
  156. #ifndef BOOST_NO_WREGEX
  157. inline bool regex_search(const wchar_t* str,
  158. const wregex& e,
  159. match_flag_type flags = match_default)
  160. {
  161. wcmatch m;
  162. return regex_search(str, str + wregex::traits_type::length(str), m, e, flags | regex_constants::match_any);
  163. }
  164. #endif
  165. inline bool regex_search(const std::string& s,
  166. const regex& e,
  167. match_flag_type flags = match_default)
  168. {
  169. smatch m;
  170. return regex_search(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
  171. }
  172. #if !defined(BOOST_NO_WREGEX)
  173. inline bool regex_search(const std::basic_string<wchar_t>& s,
  174. const wregex& e,
  175. match_flag_type flags = match_default)
  176. {
  177. wsmatch m;
  178. return regex_search(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
  179. }
  180. #endif // BOOST_NO_WREGEX
  181. #endif // partial overload
  182. #ifdef BOOST_MSVC
  183. #pragma warning(push)
  184. #pragma warning(disable: 4103)
  185. #endif
  186. #ifdef BOOST_HAS_ABI_HEADERS
  187. # include BOOST_ABI_SUFFIX
  188. #endif
  189. #ifdef BOOST_MSVC
  190. #pragma warning(pop)
  191. #endif
  192. } // namespace boost
  193. #endif // BOOST_REGEX_V4_REGEX_SEARCH_HPP