File indexing completed on 2024-11-16 09:32:57
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #ifndef BOOST_REGEX_V5_REGEX_GREP_HPP
0020 #define BOOST_REGEX_V5_REGEX_GREP_HPP
0021
0022
0023 namespace boost{
0024
0025
0026
0027
0028
0029 template <class Predicate, class BidiIterator, class charT, class traits>
0030 inline unsigned int regex_grep(Predicate foo,
0031 BidiIterator first,
0032 BidiIterator last,
0033 const basic_regex<charT, traits>& e,
0034 match_flag_type flags = match_default)
0035 {
0036 if(e.flags() & regex_constants::failbit)
0037 return false;
0038
0039 typedef typename match_results<BidiIterator>::allocator_type match_allocator_type;
0040
0041 match_results<BidiIterator> m;
0042 BOOST_REGEX_DETAIL_NS::perl_matcher<BidiIterator, match_allocator_type, traits> matcher(first, last, m, e, flags, first);
0043 unsigned int count = 0;
0044 while(matcher.find())
0045 {
0046 ++count;
0047 if(0 == foo(m))
0048 return count;
0049 if(m[0].second == last)
0050 return count;
0051 if(m.length() == 0)
0052 {
0053 if(m[0].second == last)
0054 return count;
0055
0056
0057 match_results<BidiIterator, match_allocator_type> m2(m);
0058 matcher.setf(match_not_null | match_continuous);
0059 if(matcher.find())
0060 {
0061 ++count;
0062 if(0 == foo(m))
0063 return count;
0064 }
0065 else
0066 {
0067
0068 m = m2;
0069 }
0070 matcher.unsetf((match_not_null | match_continuous) & ~flags);
0071 }
0072 }
0073 return count;
0074 }
0075
0076
0077
0078
0079 template <class Predicate, class charT, class traits>
0080 inline unsigned int regex_grep(Predicate foo, const charT* str,
0081 const basic_regex<charT, traits>& e,
0082 match_flag_type flags = match_default)
0083 {
0084 return regex_grep(foo, str, str + traits::length(str), e, flags);
0085 }
0086
0087 template <class Predicate, class ST, class SA, class charT, class traits>
0088 inline unsigned int regex_grep(Predicate foo, const std::basic_string<charT, ST, SA>& s,
0089 const basic_regex<charT, traits>& e,
0090 match_flag_type flags = match_default)
0091 {
0092 return regex_grep(foo, s.begin(), s.end(), e, flags);
0093 }
0094
0095 }
0096
0097 #endif
0098