1 // Boost string_algo library find_regex.hpp header file ---------------------------//
3 // Copyright Pavol Droba 2002-2003.
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 // See http://www.boost.org/ for updates, documentation, and revision history.
11 #ifndef BOOST_STRING_FINDER_REGEX_DETAIL_HPP
12 #define BOOST_STRING_FINDER_REGEX_DETAIL_HPP
14 #include <boost/algorithm/string/config.hpp>
15 #include <boost/regex.hpp>
17 #include <boost/range/iterator_range_core.hpp>
18 #include <boost/range/begin.hpp>
19 #include <boost/range/end.hpp>
25 // regex find functor -----------------------------------------------//
27 // regex search result
28 template<typename IteratorT>
29 struct regex_search_result :
30 public iterator_range<IteratorT>
32 typedef regex_search_result<IteratorT> type;
33 typedef iterator_range<IteratorT> base_type;
34 typedef BOOST_STRING_TYPENAME base_type::value_type value_type;
35 typedef BOOST_STRING_TYPENAME base_type::difference_type difference_type;
36 typedef BOOST_STRING_TYPENAME base_type::const_iterator const_iterator;
37 typedef BOOST_STRING_TYPENAME base_type::iterator iterator;
38 typedef boost::match_results<iterator> match_results_type;
42 // Construction from the match result
43 regex_search_result( const match_results_type& MatchResults ) :
44 base_type( MatchResults[0].first, MatchResults[0].second ),
45 m_MatchResults( MatchResults ) {}
47 // Construction of empty match. End iterator has to be specified
48 regex_search_result( IteratorT End ) :
49 base_type( End, End ) {}
51 regex_search_result( const regex_search_result& Other ) :
52 base_type( Other.begin(), Other.end() ),
53 m_MatchResults( Other.m_MatchResults ) {}
56 regex_search_result& operator=( const regex_search_result& Other )
58 base_type::operator=( Other );
59 m_MatchResults=Other.m_MatchResults;
63 // Match result retrieval
64 const match_results_type& match_results() const
66 return m_MatchResults;
71 match_results_type m_MatchResults;
76 Regex based search functor
78 template<typename RegExT>
81 typedef RegExT regex_type;
82 typedef const RegExT& regex_reference_type;
85 find_regexF( regex_reference_type Rx, match_flag_type MatchFlags = match_default ) :
86 m_Rx(Rx), m_MatchFlags(MatchFlags) {}
89 template< typename ForwardIteratorT >
90 regex_search_result<ForwardIteratorT>
92 ForwardIteratorT Begin,
93 ForwardIteratorT End ) const
95 typedef ForwardIteratorT input_iterator_type;
96 typedef regex_search_result<ForwardIteratorT> result_type;
98 // instantiate match result
99 match_results<input_iterator_type> result;
100 // search for a match
101 if ( ::boost::regex_search( Begin, End, result, m_Rx, m_MatchFlags ) )
103 // construct a result
104 return result_type( result );
109 return result_type( End );
114 regex_reference_type m_Rx; // Regexp
115 match_flag_type m_MatchFlags; // match flags
118 } // namespace detail
119 } // namespace algorithm
122 #endif // BOOST_STRING_FIND_DETAIL_HPP