regex_match.hpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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_match.hpp
  14. * VERSION see <boost/version.hpp>
  15. * DESCRIPTION: Regular expression matching algorithms.
  16. * Note this is an internal header file included
  17. * by regex.hpp, do not include on its own.
  18. */
  19. #ifndef BOOST_REGEX_MATCH_HPP
  20. #define BOOST_REGEX_MATCH_HPP
  21. namespace boost{
  22. #ifdef BOOST_MSVC
  23. #pragma warning(push)
  24. #pragma warning(disable: 4103)
  25. #endif
  26. #ifdef BOOST_HAS_ABI_HEADERS
  27. # include BOOST_ABI_PREFIX
  28. #endif
  29. #ifdef BOOST_MSVC
  30. #pragma warning(pop)
  31. #endif
  32. //
  33. // proc regex_match
  34. // returns true if the specified regular expression matches
  35. // the whole of the input. Fills in what matched in m.
  36. //
  37. template <class BidiIterator, class Allocator, class charT, class traits>
  38. bool regex_match(BidiIterator first, BidiIterator last,
  39. match_results<BidiIterator, Allocator>& m,
  40. const basic_regex<charT, traits>& e,
  41. match_flag_type flags = match_default)
  42. {
  43. BOOST_REGEX_DETAIL_NS::perl_matcher<BidiIterator, Allocator, traits> matcher(first, last, m, e, flags, first);
  44. return matcher.match();
  45. }
  46. template <class iterator, class charT, class traits>
  47. bool regex_match(iterator first, iterator last,
  48. const basic_regex<charT, traits>& e,
  49. match_flag_type flags = match_default)
  50. {
  51. match_results<iterator> m;
  52. return regex_match(first, last, m, e, flags | regex_constants::match_any);
  53. }
  54. //
  55. // query_match convenience interfaces:
  56. #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
  57. //
  58. // this isn't really a partial specialisation, but template function
  59. // overloading - if the compiler doesn't support partial specialisation
  60. // then it really won't support this either:
  61. template <class charT, class Allocator, class traits>
  62. inline bool regex_match(const charT* str,
  63. match_results<const charT*, Allocator>& m,
  64. const basic_regex<charT, traits>& e,
  65. match_flag_type flags = match_default)
  66. {
  67. return regex_match(str, str + traits::length(str), m, e, flags);
  68. }
  69. template <class ST, class SA, class Allocator, class charT, class traits>
  70. inline bool regex_match(const std::basic_string<charT, ST, SA>& s,
  71. match_results<typename std::basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
  72. const basic_regex<charT, traits>& e,
  73. match_flag_type flags = match_default)
  74. {
  75. return regex_match(s.begin(), s.end(), m, e, flags);
  76. }
  77. template <class charT, class traits>
  78. inline bool regex_match(const charT* str,
  79. const basic_regex<charT, traits>& e,
  80. match_flag_type flags = match_default)
  81. {
  82. match_results<const charT*> m;
  83. return regex_match(str, str + traits::length(str), m, e, flags | regex_constants::match_any);
  84. }
  85. template <class ST, class SA, class charT, class traits>
  86. inline bool regex_match(const std::basic_string<charT, ST, SA>& s,
  87. const basic_regex<charT, traits>& e,
  88. match_flag_type flags = match_default)
  89. {
  90. typedef typename std::basic_string<charT, ST, SA>::const_iterator iterator;
  91. match_results<iterator> m;
  92. return regex_match(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
  93. }
  94. #else // partial ordering
  95. inline bool regex_match(const char* str,
  96. cmatch& m,
  97. const regex& e,
  98. match_flag_type flags = match_default)
  99. {
  100. return regex_match(str, str + regex::traits_type::length(str), m, e, flags);
  101. }
  102. inline bool regex_match(const char* str,
  103. const regex& e,
  104. match_flag_type flags = match_default)
  105. {
  106. match_results<const char*> m;
  107. return regex_match(str, str + regex::traits_type::length(str), m, e, flags | regex_constants::match_any);
  108. }
  109. #ifndef BOOST_NO_STD_LOCALE
  110. inline bool regex_match(const char* str,
  111. cmatch& m,
  112. const basic_regex<char, cpp_regex_traits<char> >& e,
  113. match_flag_type flags = match_default)
  114. {
  115. return regex_match(str, str + regex::traits_type::length(str), m, e, flags);
  116. }
  117. inline bool regex_match(const char* str,
  118. const basic_regex<char, cpp_regex_traits<char> >& e,
  119. match_flag_type flags = match_default)
  120. {
  121. match_results<const char*> m;
  122. return regex_match(str, str + regex::traits_type::length(str), m, e, flags | regex_constants::match_any);
  123. }
  124. #endif
  125. inline bool regex_match(const char* str,
  126. cmatch& m,
  127. const basic_regex<char, c_regex_traits<char> >& e,
  128. match_flag_type flags = match_default)
  129. {
  130. return regex_match(str, str + regex::traits_type::length(str), m, e, flags);
  131. }
  132. inline bool regex_match(const char* str,
  133. const basic_regex<char, c_regex_traits<char> >& e,
  134. match_flag_type flags = match_default)
  135. {
  136. match_results<const char*> m;
  137. return regex_match(str, str + regex::traits_type::length(str), m, e, flags | regex_constants::match_any);
  138. }
  139. #if defined(_WIN32) && !defined(BOOST_REGEX_NO_W32)
  140. inline bool regex_match(const char* str,
  141. cmatch& m,
  142. const basic_regex<char, w32_regex_traits<char> >& e,
  143. match_flag_type flags = match_default)
  144. {
  145. return regex_match(str, str + regex::traits_type::length(str), m, e, flags);
  146. }
  147. inline bool regex_match(const char* str,
  148. const basic_regex<char, w32_regex_traits<char> >& e,
  149. match_flag_type flags = match_default)
  150. {
  151. match_results<const char*> m;
  152. return regex_match(str, str + regex::traits_type::length(str), m, e, flags | regex_constants::match_any);
  153. }
  154. #endif
  155. #ifndef BOOST_NO_WREGEX
  156. inline bool regex_match(const wchar_t* str,
  157. wcmatch& m,
  158. const wregex& e,
  159. match_flag_type flags = match_default)
  160. {
  161. return regex_match(str, str + wregex::traits_type::length(str), m, e, flags);
  162. }
  163. inline bool regex_match(const wchar_t* str,
  164. const wregex& e,
  165. match_flag_type flags = match_default)
  166. {
  167. match_results<const wchar_t*> m;
  168. return regex_match(str, str + wregex::traits_type::length(str), m, e, flags | regex_constants::match_any);
  169. }
  170. #ifndef BOOST_NO_STD_LOCALE
  171. inline bool regex_match(const wchar_t* str,
  172. wcmatch& m,
  173. const basic_regex<wchar_t, cpp_regex_traits<wchar_t> >& e,
  174. match_flag_type flags = match_default)
  175. {
  176. return regex_match(str, str + wregex::traits_type::length(str), m, e, flags);
  177. }
  178. inline bool regex_match(const wchar_t* str,
  179. const basic_regex<wchar_t, cpp_regex_traits<wchar_t> >& e,
  180. match_flag_type flags = match_default)
  181. {
  182. match_results<const wchar_t*> m;
  183. return regex_match(str, str + wregex::traits_type::length(str), m, e, flags | regex_constants::match_any);
  184. }
  185. #endif
  186. inline bool regex_match(const wchar_t* str,
  187. wcmatch& m,
  188. const basic_regex<wchar_t, c_regex_traits<wchar_t> >& e,
  189. match_flag_type flags = match_default)
  190. {
  191. return regex_match(str, str + wregex::traits_type::length(str), m, e, flags);
  192. }
  193. inline bool regex_match(const wchar_t* str,
  194. const basic_regex<wchar_t, c_regex_traits<wchar_t> >& e,
  195. match_flag_type flags = match_default)
  196. {
  197. match_results<const wchar_t*> m;
  198. return regex_match(str, str + wregex::traits_type::length(str), m, e, flags | regex_constants::match_any);
  199. }
  200. #if defined(_WIN32) && !defined(BOOST_REGEX_NO_W32)
  201. inline bool regex_match(const wchar_t* str,
  202. wcmatch& m,
  203. const basic_regex<wchar_t, w32_regex_traits<wchar_t> >& e,
  204. match_flag_type flags = match_default)
  205. {
  206. return regex_match(str, str + wregex::traits_type::length(str), m, e, flags);
  207. }
  208. inline bool regex_match(const wchar_t* str,
  209. const basic_regex<wchar_t, w32_regex_traits<wchar_t> >& e,
  210. match_flag_type flags = match_default)
  211. {
  212. match_results<const wchar_t*> m;
  213. return regex_match(str, str + wregex::traits_type::length(str), m, e, flags | regex_constants::match_any);
  214. }
  215. #endif
  216. #endif
  217. inline bool regex_match(const std::string& s,
  218. smatch& m,
  219. const regex& e,
  220. match_flag_type flags = match_default)
  221. {
  222. return regex_match(s.begin(), s.end(), m, e, flags);
  223. }
  224. inline bool regex_match(const std::string& s,
  225. const regex& e,
  226. match_flag_type flags = match_default)
  227. {
  228. match_results<std::string::const_iterator> m;
  229. return regex_match(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
  230. }
  231. #ifndef BOOST_NO_STD_LOCALE
  232. inline bool regex_match(const std::string& s,
  233. smatch& m,
  234. const basic_regex<char, cpp_regex_traits<char> >& e,
  235. match_flag_type flags = match_default)
  236. {
  237. return regex_match(s.begin(), s.end(), m, e, flags);
  238. }
  239. inline bool regex_match(const std::string& s,
  240. const basic_regex<char, cpp_regex_traits<char> >& e,
  241. match_flag_type flags = match_default)
  242. {
  243. match_results<std::string::const_iterator> m;
  244. return regex_match(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
  245. }
  246. #endif
  247. inline bool regex_match(const std::string& s,
  248. smatch& m,
  249. const basic_regex<char, c_regex_traits<char> >& e,
  250. match_flag_type flags = match_default)
  251. {
  252. return regex_match(s.begin(), s.end(), m, e, flags);
  253. }
  254. inline bool regex_match(const std::string& s,
  255. const basic_regex<char, c_regex_traits<char> >& e,
  256. match_flag_type flags = match_default)
  257. {
  258. match_results<std::string::const_iterator> m;
  259. return regex_match(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
  260. }
  261. #if defined(_WIN32) && !defined(BOOST_REGEX_NO_W32)
  262. inline bool regex_match(const std::string& s,
  263. smatch& m,
  264. const basic_regex<char, w32_regex_traits<char> >& e,
  265. match_flag_type flags = match_default)
  266. {
  267. return regex_match(s.begin(), s.end(), m, e, flags);
  268. }
  269. inline bool regex_match(const std::string& s,
  270. const basic_regex<char, w32_regex_traits<char> >& e,
  271. match_flag_type flags = match_default)
  272. {
  273. match_results<std::string::const_iterator> m;
  274. return regex_match(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
  275. }
  276. #endif
  277. #if !defined(BOOST_NO_WREGEX)
  278. inline bool regex_match(const std::basic_string<wchar_t>& s,
  279. match_results<std::basic_string<wchar_t>::const_iterator>& m,
  280. const wregex& e,
  281. match_flag_type flags = match_default)
  282. {
  283. return regex_match(s.begin(), s.end(), m, e, flags);
  284. }
  285. inline bool regex_match(const std::basic_string<wchar_t>& s,
  286. const wregex& e,
  287. match_flag_type flags = match_default)
  288. {
  289. match_results<std::basic_string<wchar_t>::const_iterator> m;
  290. return regex_match(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
  291. }
  292. #ifndef BOOST_NO_STD_LOCALE
  293. inline bool regex_match(const std::basic_string<wchar_t>& s,
  294. match_results<std::basic_string<wchar_t>::const_iterator>& m,
  295. const basic_regex<wchar_t, cpp_regex_traits<wchar_t> >& e,
  296. match_flag_type flags = match_default)
  297. {
  298. return regex_match(s.begin(), s.end(), m, e, flags);
  299. }
  300. inline bool regex_match(const std::basic_string<wchar_t>& s,
  301. const basic_regex<wchar_t, cpp_regex_traits<wchar_t> >& e,
  302. match_flag_type flags = match_default)
  303. {
  304. match_results<std::basic_string<wchar_t>::const_iterator> m;
  305. return regex_match(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
  306. }
  307. #endif
  308. inline bool regex_match(const std::basic_string<wchar_t>& s,
  309. match_results<std::basic_string<wchar_t>::const_iterator>& m,
  310. const basic_regex<wchar_t, c_regex_traits<wchar_t> >& e,
  311. match_flag_type flags = match_default)
  312. {
  313. return regex_match(s.begin(), s.end(), m, e, flags);
  314. }
  315. inline bool regex_match(const std::basic_string<wchar_t>& s,
  316. const basic_regex<wchar_t, c_regex_traits<wchar_t> >& e,
  317. match_flag_type flags = match_default)
  318. {
  319. match_results<std::basic_string<wchar_t>::const_iterator> m;
  320. return regex_match(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
  321. }
  322. #if defined(_WIN32) && !defined(BOOST_REGEX_NO_W32)
  323. inline bool regex_match(const std::basic_string<wchar_t>& s,
  324. match_results<std::basic_string<wchar_t>::const_iterator>& m,
  325. const basic_regex<wchar_t, w32_regex_traits<wchar_t> >& e,
  326. match_flag_type flags = match_default)
  327. {
  328. return regex_match(s.begin(), s.end(), m, e, flags);
  329. }
  330. inline bool regex_match(const std::basic_string<wchar_t>& s,
  331. const basic_regex<wchar_t, w32_regex_traits<wchar_t> >& e,
  332. match_flag_type flags = match_default)
  333. {
  334. match_results<std::basic_string<wchar_t>::const_iterator> m;
  335. return regex_match(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
  336. }
  337. #endif
  338. #endif
  339. #endif
  340. #ifdef BOOST_MSVC
  341. #pragma warning(push)
  342. #pragma warning(disable: 4103)
  343. #endif
  344. #ifdef BOOST_HAS_ABI_HEADERS
  345. # include BOOST_ABI_SUFFIX
  346. #endif
  347. #ifdef BOOST_MSVC
  348. #pragma warning(pop)
  349. #endif
  350. } // namespace boost
  351. #endif // BOOST_REGEX_MATCH_HPP