Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:51:25

0001 /*
0002  *
0003  * Copyright (c) 1998-2002
0004  * John Maddock
0005  *
0006  * Use, modification and distribution are subject to the 
0007  * Boost Software License, Version 1.0. (See accompanying file 
0008  * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009  *
0010  */
0011 
0012  /*
0013   *   LOCATION:    see http://www.boost.org for most recent version.
0014   *   FILE         regex_grep.hpp
0015   *   VERSION      see <boost/version.hpp>
0016   *   DESCRIPTION: Provides regex_grep implementation.
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 // regex_grep:
0038 // find all non-overlapping matches within the sequence first last:
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; // caller doesn't want to go on
0060       if(m[0].second == last)
0061          return count; // we've reached the end, don't try and find an extra null match.
0062       if(m.length() == 0)
0063       {
0064          if(m[0].second == last)
0065             return count;
0066          // we found a NULL-match, now try to find
0067          // a non-NULL one at the same position:
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             // reset match back to where it was:
0079             m = m2;
0080          }
0081          matcher.unsetf((match_not_null | match_continuous) & ~flags);
0082       }
0083    }
0084    return count;
0085 }
0086 
0087 //
0088 // regex_grep convenience interfaces:
0089 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
0090 //
0091 // this isn't really a partial specialisation, but template function
0092 // overloading - if the compiler doesn't support partial specialisation
0093 // then it really won't support this either:
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  // partial specialisation
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 } // namespace boost
0153 
0154 #endif  // BOOST_REGEX_V4_REGEX_GREP_HPP
0155