Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-17 09:38:58

0001 //  Boost string_algo library find_regex.hpp header file  ---------------------------//
0002 
0003 //  Copyright Pavol Droba 2002-2003.
0004 //
0005 // Distributed under the Boost Software License, Version 1.0.
0006 //    (See accompanying file LICENSE_1_0.txt or copy at
0007 //          http://www.boost.org/LICENSE_1_0.txt)
0008 
0009 //  See http://www.boost.org/ for updates, documentation, and revision history.
0010 
0011 #ifndef BOOST_STRING_FINDER_REGEX_DETAIL_HPP
0012 #define BOOST_STRING_FINDER_REGEX_DETAIL_HPP
0013 
0014 #include <boost/algorithm/string/config.hpp>
0015 #include <boost/regex.hpp>
0016 
0017 #include <boost/range/iterator_range_core.hpp>
0018 #include <boost/range/begin.hpp>
0019 #include <boost/range/end.hpp>
0020 
0021 namespace boost {
0022     namespace algorithm {
0023         namespace detail {
0024 
0025 //  regex find functor -----------------------------------------------//
0026 
0027             // regex search result
0028             template<typename IteratorT>
0029             struct regex_search_result : 
0030                 public iterator_range<IteratorT>
0031             {
0032                 typedef regex_search_result<IteratorT> type;
0033                 typedef iterator_range<IteratorT> base_type;
0034                 typedef BOOST_STRING_TYPENAME base_type::value_type value_type;
0035                 typedef BOOST_STRING_TYPENAME base_type::difference_type difference_type;
0036                 typedef BOOST_STRING_TYPENAME base_type::const_iterator const_iterator;
0037                 typedef BOOST_STRING_TYPENAME base_type::iterator iterator;
0038                 typedef boost::match_results<iterator> match_results_type;
0039 
0040                 // Construction
0041 
0042                 // Construction from the match result
0043                 regex_search_result( const match_results_type& MatchResults ) :
0044                     base_type( MatchResults[0].first, MatchResults[0].second ),
0045                     m_MatchResults( MatchResults ) {}
0046                 
0047                 // Construction of empty match. End iterator has to be specified
0048                 regex_search_result( IteratorT End ) :
0049                     base_type( End, End ) {}
0050 
0051                 regex_search_result( const regex_search_result& Other ) :
0052                     base_type( Other.begin(), Other.end() ),
0053                     m_MatchResults( Other.m_MatchResults ) {}
0054 
0055                 // Assignment
0056                 regex_search_result& operator=( const regex_search_result& Other )
0057                 {
0058                     base_type::operator=( Other );
0059                     m_MatchResults=Other.m_MatchResults;
0060                     return *this;
0061                 }
0062 
0063                 // Match result retrieval
0064                 const match_results_type& match_results() const
0065                 {
0066                     return m_MatchResults;
0067                 }
0068 
0069             private:
0070                 // Saved match result
0071                 match_results_type m_MatchResults;
0072             };
0073 
0074             // find_regex
0075             /*
0076                 Regex based search functor
0077             */
0078             template<typename RegExT>
0079             struct find_regexF
0080             {
0081                 typedef RegExT regex_type;
0082                 typedef const RegExT& regex_reference_type;
0083                     
0084                 // Construction
0085                 find_regexF( regex_reference_type Rx, match_flag_type MatchFlags = match_default ) : 
0086                     m_Rx(Rx), m_MatchFlags(MatchFlags) {}   
0087 
0088                 // Operation
0089                 template< typename ForwardIteratorT >
0090                 regex_search_result<ForwardIteratorT>
0091                 operator()( 
0092                     ForwardIteratorT Begin, 
0093                     ForwardIteratorT End ) const
0094                 {
0095                     typedef ForwardIteratorT input_iterator_type;
0096                     typedef regex_search_result<ForwardIteratorT> result_type;
0097 
0098                     // instantiate match result
0099                     match_results<input_iterator_type> result;
0100                     // search for a match
0101                     if ( ::boost::regex_search( Begin, End, result, m_Rx, m_MatchFlags ) )
0102                     {
0103                         // construct a result
0104                         return result_type( result );
0105                     }
0106                     else
0107                     {
0108                         // empty result
0109                         return result_type( End );
0110                     }
0111                 }
0112 
0113             private:
0114                 regex_reference_type m_Rx; // Regexp
0115                 match_flag_type m_MatchFlags;     // match flags
0116             };
0117 
0118         } // namespace detail
0119     } // namespace algorithm
0120 } // namespace boost
0121 
0122 #endif  // BOOST_STRING_FIND_DETAIL_HPP