Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-16 09:32:57

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_V5_REGEX_GREP_HPP
0020 #define BOOST_REGEX_V5_REGEX_GREP_HPP
0021 
0022 
0023 namespace boost{
0024 
0025 //
0026 // regex_grep:
0027 // find all non-overlapping matches within the sequence first last:
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; // caller doesn't want to go on
0049       if(m[0].second == last)
0050          return count; // we've reached the end, don't try and find an extra null match.
0051       if(m.length() == 0)
0052       {
0053          if(m[0].second == last)
0054             return count;
0055          // we found a NULL-match, now try to find
0056          // a non-NULL one at the same position:
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             // reset match back to where it was:
0068             m = m2;
0069          }
0070          matcher.unsetf((match_not_null | match_continuous) & ~flags);
0071       }
0072    }
0073    return count;
0074 }
0075 
0076 //
0077 // regex_grep convenience interfaces:
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 } // namespace boost
0096 
0097 #endif  // BOOST_REGEX_V5_REGEX_GREP_HPP
0098