regex_match.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. #include <boost/regex/v5/match_results.hpp>
  22. #include <boost/regex/v5/perl_matcher.hpp>
  23. namespace boost{
  24. //
  25. // proc regex_match
  26. // returns true if the specified regular expression matches
  27. // the whole of the input. Fills in what matched in m.
  28. //
  29. BOOST_REGEX_MODULE_EXPORT template <class BidiIterator, class Allocator, class charT, class traits>
  30. bool regex_match(BidiIterator first, BidiIterator last,
  31. match_results<BidiIterator, Allocator>& m,
  32. const basic_regex<charT, traits>& e,
  33. match_flag_type flags = match_default)
  34. {
  35. BOOST_REGEX_DETAIL_NS::perl_matcher<BidiIterator, Allocator, traits> matcher(first, last, m, e, flags, first);
  36. return BOOST_REGEX_DETAIL_NS::factory_match(matcher);
  37. }
  38. BOOST_REGEX_MODULE_EXPORT template <class iterator, class charT, class traits>
  39. bool regex_match(iterator first, iterator last,
  40. const basic_regex<charT, traits>& e,
  41. match_flag_type flags = match_default)
  42. {
  43. match_results<iterator> m;
  44. return regex_match(first, last, m, e, flags | regex_constants::match_any);
  45. }
  46. //
  47. // query_match convenience interfaces:
  48. //
  49. BOOST_REGEX_MODULE_EXPORT template <class charT, class Allocator, class traits>
  50. inline bool regex_match(const charT* str,
  51. match_results<const charT*, Allocator>& m,
  52. const basic_regex<charT, traits>& e,
  53. match_flag_type flags = match_default)
  54. {
  55. return regex_match(str, str + traits::length(str), m, e, flags);
  56. }
  57. BOOST_REGEX_MODULE_EXPORT template <class ST, class SA, class Allocator, class charT, class traits>
  58. inline bool regex_match(const std::basic_string<charT, ST, SA>& s,
  59. match_results<typename std::basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
  60. const basic_regex<charT, traits>& e,
  61. match_flag_type flags = match_default)
  62. {
  63. return regex_match(s.begin(), s.end(), m, e, flags);
  64. }
  65. BOOST_REGEX_MODULE_EXPORT template <class charT, class traits>
  66. inline bool regex_match(const charT* str,
  67. const basic_regex<charT, traits>& e,
  68. match_flag_type flags = match_default)
  69. {
  70. match_results<const charT*> m;
  71. return regex_match(str, str + traits::length(str), m, e, flags | regex_constants::match_any);
  72. }
  73. BOOST_REGEX_MODULE_EXPORT template <class ST, class SA, class charT, class traits>
  74. inline bool regex_match(const std::basic_string<charT, ST, SA>& s,
  75. const basic_regex<charT, traits>& e,
  76. match_flag_type flags = match_default)
  77. {
  78. typedef typename std::basic_string<charT, ST, SA>::const_iterator iterator;
  79. match_results<iterator> m;
  80. return regex_match(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
  81. }
  82. } // namespace boost
  83. #endif // BOOST_REGEX_MATCH_HPP