File indexing completed on 2025-01-18 09:51:25
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #ifndef BOOST_REGEX_V4_REGEX_GREP_HPP
0020 #define BOOST_REGEX_V4_REGEX_GREP_HPP
0021
0022
0023 namespace boost{
0024
0025 #ifdef BOOST_MSVC
0026 #pragma warning(push)
0027 #pragma warning(disable: 4103)
0028 #endif
0029 #ifdef BOOST_HAS_ABI_HEADERS
0030 # include BOOST_ABI_PREFIX
0031 #endif
0032 #ifdef BOOST_MSVC
0033 #pragma warning(pop)
0034 #endif
0035
0036
0037
0038
0039
0040 template <class Predicate, class BidiIterator, class charT, class traits>
0041 inline unsigned int regex_grep(Predicate foo,
0042 BidiIterator first,
0043 BidiIterator last,
0044 const basic_regex<charT, traits>& e,
0045 match_flag_type flags = match_default)
0046 {
0047 if(e.flags() & regex_constants::failbit)
0048 return false;
0049
0050 typedef typename match_results<BidiIterator>::allocator_type match_allocator_type;
0051
0052 match_results<BidiIterator> m;
0053 BOOST_REGEX_DETAIL_NS::perl_matcher<BidiIterator, match_allocator_type, traits> matcher(first, last, m, e, flags, first);
0054 unsigned int count = 0;
0055 while(matcher.find())
0056 {
0057 ++count;
0058 if(0 == foo(m))
0059 return count;
0060 if(m[0].second == last)
0061 return count;
0062 if(m.length() == 0)
0063 {
0064 if(m[0].second == last)
0065 return count;
0066
0067
0068 match_results<BidiIterator, match_allocator_type> m2(m);
0069 matcher.setf(match_not_null | match_continuous);
0070 if(matcher.find())
0071 {
0072 ++count;
0073 if(0 == foo(m))
0074 return count;
0075 }
0076 else
0077 {
0078
0079 m = m2;
0080 }
0081 matcher.unsetf((match_not_null | match_continuous) & ~flags);
0082 }
0083 }
0084 return count;
0085 }
0086
0087
0088
0089 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
0090
0091
0092
0093
0094 template <class Predicate, class charT, class traits>
0095 inline unsigned int regex_grep(Predicate foo, const charT* str,
0096 const basic_regex<charT, traits>& e,
0097 match_flag_type flags = match_default)
0098 {
0099 return regex_grep(foo, str, str + traits::length(str), e, flags);
0100 }
0101
0102 template <class Predicate, class ST, class SA, class charT, class traits>
0103 inline unsigned int regex_grep(Predicate foo, const std::basic_string<charT, ST, SA>& s,
0104 const basic_regex<charT, traits>& e,
0105 match_flag_type flags = match_default)
0106 {
0107 return regex_grep(foo, s.begin(), s.end(), e, flags);
0108 }
0109 #else
0110 inline unsigned int regex_grep(bool (*foo)(const cmatch&), const char* str,
0111 const regex& e,
0112 match_flag_type flags = match_default)
0113 {
0114 return regex_grep(foo, str, str + regex::traits_type::length(str), e, flags);
0115 }
0116 #ifndef BOOST_NO_WREGEX
0117 inline unsigned int regex_grep(bool (*foo)(const wcmatch&), const wchar_t* str,
0118 const wregex& e,
0119 match_flag_type flags = match_default)
0120 {
0121 return regex_grep(foo, str, str + wregex::traits_type::length(str), e, flags);
0122 }
0123 #endif
0124 inline unsigned int regex_grep(bool (*foo)(const match_results<std::string::const_iterator>&), const std::string& s,
0125 const regex& e,
0126 match_flag_type flags = match_default)
0127 {
0128 return regex_grep(foo, s.begin(), s.end(), e, flags);
0129 }
0130 #if !defined(BOOST_NO_WREGEX)
0131 inline unsigned int regex_grep(bool (*foo)(const match_results<std::basic_string<wchar_t>::const_iterator>&),
0132 const std::basic_string<wchar_t>& s,
0133 const wregex& e,
0134 match_flag_type flags = match_default)
0135 {
0136 return regex_grep(foo, s.begin(), s.end(), e, flags);
0137 }
0138 #endif
0139 #endif
0140
0141 #ifdef BOOST_MSVC
0142 #pragma warning(push)
0143 #pragma warning(disable: 4103)
0144 #endif
0145 #ifdef BOOST_HAS_ABI_HEADERS
0146 # include BOOST_ABI_SUFFIX
0147 #endif
0148 #ifdef BOOST_MSVC
0149 #pragma warning(pop)
0150 #endif
0151
0152 }
0153
0154 #endif
0155