regex_search.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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_V5_REGEX_SEARCH_HPP
  18. #define BOOST_REGEX_V5_REGEX_SEARCH_HPP
  19. namespace boost{
  20. template <class BidiIterator, class Allocator, class charT, class traits>
  21. bool regex_search(BidiIterator first, BidiIterator last,
  22. match_results<BidiIterator, Allocator>& m,
  23. const basic_regex<charT, traits>& e,
  24. match_flag_type flags = match_default)
  25. {
  26. return regex_search(first, last, m, e, flags, first);
  27. }
  28. template <class BidiIterator, class Allocator, class charT, class traits>
  29. bool regex_search(BidiIterator first, BidiIterator last,
  30. match_results<BidiIterator, Allocator>& m,
  31. const basic_regex<charT, traits>& e,
  32. match_flag_type flags,
  33. BidiIterator base)
  34. {
  35. if(e.flags() & regex_constants::failbit)
  36. return false;
  37. BOOST_REGEX_DETAIL_NS::perl_matcher<BidiIterator, Allocator, traits> matcher(first, last, m, e, flags, base);
  38. return matcher.find();
  39. }
  40. //
  41. // regex_search convenience interfaces:
  42. //
  43. template <class charT, class Allocator, class traits>
  44. inline bool regex_search(const charT* str,
  45. match_results<const charT*, Allocator>& m,
  46. const basic_regex<charT, traits>& e,
  47. match_flag_type flags = match_default)
  48. {
  49. return regex_search(str, str + traits::length(str), m, e, flags);
  50. }
  51. template <class ST, class SA, class Allocator, class charT, class traits>
  52. inline bool regex_search(const std::basic_string<charT, ST, SA>& s,
  53. match_results<typename std::basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
  54. const basic_regex<charT, traits>& e,
  55. match_flag_type flags = match_default)
  56. {
  57. return regex_search(s.begin(), s.end(), m, e, flags);
  58. }
  59. template <class BidiIterator, class charT, class traits>
  60. bool regex_search(BidiIterator first, BidiIterator last,
  61. const basic_regex<charT, traits>& e,
  62. match_flag_type flags = match_default)
  63. {
  64. if(e.flags() & regex_constants::failbit)
  65. return false;
  66. match_results<BidiIterator> m;
  67. typedef typename match_results<BidiIterator>::allocator_type match_alloc_type;
  68. BOOST_REGEX_DETAIL_NS::perl_matcher<BidiIterator, match_alloc_type, traits> matcher(first, last, m, e, flags | regex_constants::match_any, first);
  69. return matcher.find();
  70. }
  71. template <class charT, class traits>
  72. inline bool regex_search(const charT* str,
  73. const basic_regex<charT, traits>& e,
  74. match_flag_type flags = match_default)
  75. {
  76. return regex_search(str, str + traits::length(str), e, flags);
  77. }
  78. template <class ST, class SA, class charT, class traits>
  79. inline bool regex_search(const std::basic_string<charT, ST, SA>& s,
  80. const basic_regex<charT, traits>& e,
  81. match_flag_type flags = match_default)
  82. {
  83. return regex_search(s.begin(), s.end(), e, flags);
  84. }
  85. } // namespace boost
  86. #endif // BOOST_REGEX_V5_REGEX_SEARCH_HPP