regex_match.hpp 3.2 KB

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