3 * Copyright (c) 1998-2002
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)
13 * LOCATION: see http://www.boost.org for most recent version.
15 * VERSION see <boost/version.hpp>
16 * DESCRIPTION: Provides regex_grep implementation.
19 #ifndef BOOST_REGEX_V4_REGEX_GREP_HPP
20 #define BOOST_REGEX_V4_REGEX_GREP_HPP
25 #ifdef BOOST_HAS_ABI_HEADERS
26 # include BOOST_ABI_PREFIX
31 // find all non-overlapping matches within the sequence first last:
33 template <class Predicate, class BidiIterator, class charT, class traits>
34 inline unsigned int regex_grep(Predicate foo,
37 const basic_regex<charT, traits>& e,
38 match_flag_type flags = match_default)
40 if(e.flags() & regex_constants::failbit)
43 typedef typename match_results<BidiIterator>::allocator_type match_allocator_type;
45 match_results<BidiIterator> m;
46 re_detail::perl_matcher<BidiIterator, match_allocator_type, traits> matcher(first, last, m, e, flags, first);
47 unsigned int count = 0;
52 return count; // caller doesn't want to go on
53 if(m[0].second == last)
54 return count; // we've reached the end, don't try and find an extra null match.
57 if(m[0].second == last)
59 // we found a NULL-match, now try to find
60 // a non-NULL one at the same position:
61 match_results<BidiIterator, match_allocator_type> m2(m);
62 matcher.setf(match_not_null | match_continuous);
71 // reset match back to where it was:
74 matcher.unsetf((match_not_null | match_continuous) & ~flags);
81 // regex_grep convenience interfaces:
82 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
84 // this isn't really a partial specialisation, but template function
85 // overloading - if the compiler doesn't support partial specialisation
86 // then it really won't support this either:
87 template <class Predicate, class charT, class traits>
88 inline unsigned int regex_grep(Predicate foo, const charT* str,
89 const basic_regex<charT, traits>& e,
90 match_flag_type flags = match_default)
92 return regex_grep(foo, str, str + traits::length(str), e, flags);
95 template <class Predicate, class ST, class SA, class charT, class traits>
96 inline unsigned int regex_grep(Predicate foo, const std::basic_string<charT, ST, SA>& s,
97 const basic_regex<charT, traits>& e,
98 match_flag_type flags = match_default)
100 return regex_grep(foo, s.begin(), s.end(), e, flags);
102 #else // partial specialisation
103 inline unsigned int regex_grep(bool (*foo)(const cmatch&), const char* str,
105 match_flag_type flags = match_default)
107 return regex_grep(foo, str, str + regex::traits_type::length(str), e, flags);
109 #ifndef BOOST_NO_WREGEX
110 inline unsigned int regex_grep(bool (*foo)(const wcmatch&), const wchar_t* str,
112 match_flag_type flags = match_default)
114 return regex_grep(foo, str, str + wregex::traits_type::length(str), e, flags);
117 inline unsigned int regex_grep(bool (*foo)(const match_results<std::string::const_iterator>&), const std::string& s,
119 match_flag_type flags = match_default)
121 return regex_grep(foo, s.begin(), s.end(), e, flags);
123 #if !defined(BOOST_NO_WREGEX)
124 inline unsigned int regex_grep(bool (*foo)(const match_results<std::basic_string<wchar_t>::const_iterator>&),
125 const std::basic_string<wchar_t>& s,
127 match_flag_type flags = match_default)
129 return regex_grep(foo, s.begin(), s.end(), e, flags);
134 #ifdef BOOST_HAS_ABI_HEADERS
135 # include BOOST_ABI_SUFFIX
140 #endif // BOOST_REGEX_V4_REGEX_GREP_HPP