1 // Boost string_algo library find_regex.hpp header file ---------------------------//
3 // Copyright Pavol Droba 2002-2003. Use, modification and
4 // distribution is subject to the Boost Software License, Version
5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 // See http://www.boost.org for updates, documentation, and revision history.
10 #ifndef BOOST_STRING_FINDER_REGEX_DETAIL_HPP
11 #define BOOST_STRING_FINDER_REGEX_DETAIL_HPP
13 #include <boost/algorithm/string/config.hpp>
14 #include <boost/regex.hpp>
16 #include <boost/range/iterator_range.hpp>
17 #include <boost/range/begin.hpp>
18 #include <boost/range/end.hpp>
24 // regex find functor -----------------------------------------------//
26 // regex search result
27 template<typename IteratorT>
28 struct regex_search_result :
29 public iterator_range<IteratorT>
31 typedef regex_search_result<IteratorT> type;
32 typedef iterator_range<IteratorT> base_type;
33 typedef BOOST_STRING_TYPENAME base_type::value_type value_type;
34 typedef BOOST_STRING_TYPENAME base_type::difference_type difference_type;
35 typedef BOOST_STRING_TYPENAME base_type::const_iterator const_iterator;
36 typedef BOOST_STRING_TYPENAME base_type::iterator iterator;
37 typedef boost::match_results<iterator> match_results_type;
41 // Construction from the match result
42 regex_search_result( const match_results_type& MatchResults ) :
43 base_type( MatchResults[0].first, MatchResults[0].second ),
44 m_MatchResults( MatchResults ) {}
46 // Construction of empty match. End iterator has to be specified
47 regex_search_result( IteratorT End ) :
48 base_type( End, End ) {}
50 regex_search_result( const regex_search_result& Other ) :
51 base_type( Other.begin(), Other.end() ),
52 m_MatchResults( Other.m_MatchResults ) {}
55 regex_search_result& operator=( const regex_search_result& Other )
57 base_type::operator=( Other );
58 m_MatchResults=Other.m_MatchResults;
62 // Match result retrival
63 const match_results_type& match_results() const
65 return m_MatchResults;
70 match_results_type m_MatchResults;
75 Regex based search functor
77 template<typename RegExT>
80 typedef RegExT regex_type;
81 typedef const RegExT& regex_reference_type;
84 find_regexF( regex_reference_type Rx, match_flag_type MatchFlags = match_default ) :
85 m_Rx(Rx), m_MatchFlags(MatchFlags) {}
88 template< typename ForwardIteratorT >
89 regex_search_result<ForwardIteratorT>
91 ForwardIteratorT Begin,
92 ForwardIteratorT End ) const
94 typedef ForwardIteratorT input_iterator_type;
95 typedef regex_search_result<ForwardIteratorT> result_type;
97 // instantiate match result
98 match_results<input_iterator_type> result;
100 if ( regex_search( Begin, End, result, m_Rx, m_MatchFlags ) )
102 // construct a result
103 return result_type( result );
108 return result_type( End );
113 regex_reference_type m_Rx; // Regexp
114 match_flag_type m_MatchFlags; // match flags
117 } // namespace detail
118 } // namespace algorithm
121 #endif // BOOST_STRING_FIND_DETAIL_HPP