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
27 #pragma warning(disable: 4103)
29 #ifdef BOOST_HAS_ABI_HEADERS
30 # include BOOST_ABI_PREFIX
38 // find all non-overlapping matches within the sequence first last:
40 template <class Predicate, class BidiIterator, class charT, class traits>
41 inline unsigned int regex_grep(Predicate foo,
44 const basic_regex<charT, traits>& e,
45 match_flag_type flags = match_default)
47 if(e.flags() & regex_constants::failbit)
50 typedef typename match_results<BidiIterator>::allocator_type match_allocator_type;
52 match_results<BidiIterator> m;
53 re_detail::perl_matcher<BidiIterator, match_allocator_type, traits> matcher(first, last, m, e, flags, first);
54 unsigned int count = 0;
59 return count; // caller doesn't want to go on
60 if(m[0].second == last)
61 return count; // we've reached the end, don't try and find an extra null match.
64 if(m[0].second == last)
66 // we found a NULL-match, now try to find
67 // a non-NULL one at the same position:
68 match_results<BidiIterator, match_allocator_type> m2(m);
69 matcher.setf(match_not_null | match_continuous);
78 // reset match back to where it was:
81 matcher.unsetf((match_not_null | match_continuous) & ~flags);
88 // regex_grep convenience interfaces:
89 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
91 // this isn't really a partial specialisation, but template function
92 // overloading - if the compiler doesn't support partial specialisation
93 // then it really won't support this either:
94 template <class Predicate, class charT, class traits>
95 inline unsigned int regex_grep(Predicate foo, const charT* str,
96 const basic_regex<charT, traits>& e,
97 match_flag_type flags = match_default)
99 return regex_grep(foo, str, str + traits::length(str), e, flags);
102 template <class Predicate, class ST, class SA, class charT, class traits>
103 inline unsigned int regex_grep(Predicate foo, const std::basic_string<charT, ST, SA>& s,
104 const basic_regex<charT, traits>& e,
105 match_flag_type flags = match_default)
107 return regex_grep(foo, s.begin(), s.end(), e, flags);
109 #else // partial specialisation
110 inline unsigned int regex_grep(bool (*foo)(const cmatch&), const char* str,
112 match_flag_type flags = match_default)
114 return regex_grep(foo, str, str + regex::traits_type::length(str), e, flags);
116 #ifndef BOOST_NO_WREGEX
117 inline unsigned int regex_grep(bool (*foo)(const wcmatch&), const wchar_t* str,
119 match_flag_type flags = match_default)
121 return regex_grep(foo, str, str + wregex::traits_type::length(str), e, flags);
124 inline unsigned int regex_grep(bool (*foo)(const match_results<std::string::const_iterator>&), const std::string& s,
126 match_flag_type flags = match_default)
128 return regex_grep(foo, s.begin(), s.end(), e, flags);
130 #if !defined(BOOST_NO_WREGEX)
131 inline unsigned int regex_grep(bool (*foo)(const match_results<std::basic_string<wchar_t>::const_iterator>&),
132 const std::basic_string<wchar_t>& s,
134 match_flag_type flags = match_default)
136 return regex_grep(foo, s.begin(), s.end(), e, flags);
142 #pragma warning(push)
143 #pragma warning(disable: 4103)
145 #ifdef BOOST_HAS_ABI_HEADERS
146 # include BOOST_ABI_SUFFIX
154 #endif // BOOST_REGEX_V4_REGEX_GREP_HPP