Chris@16
|
1 // Boost string_algo library find_regex.hpp header file ---------------------------//
|
Chris@16
|
2
|
Chris@16
|
3 // Copyright Pavol Droba 2002-2003.
|
Chris@16
|
4 //
|
Chris@16
|
5 // Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
6 // (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
7 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
8
|
Chris@16
|
9 // See http://www.boost.org/ for updates, documentation, and revision history.
|
Chris@16
|
10
|
Chris@16
|
11 #ifndef BOOST_STRING_FINDER_REGEX_DETAIL_HPP
|
Chris@16
|
12 #define BOOST_STRING_FINDER_REGEX_DETAIL_HPP
|
Chris@16
|
13
|
Chris@16
|
14 #include <boost/algorithm/string/config.hpp>
|
Chris@16
|
15 #include <boost/regex.hpp>
|
Chris@16
|
16
|
Chris@16
|
17 #include <boost/range/iterator_range_core.hpp>
|
Chris@16
|
18 #include <boost/range/begin.hpp>
|
Chris@16
|
19 #include <boost/range/end.hpp>
|
Chris@16
|
20
|
Chris@16
|
21 namespace boost {
|
Chris@16
|
22 namespace algorithm {
|
Chris@16
|
23 namespace detail {
|
Chris@16
|
24
|
Chris@16
|
25 // regex find functor -----------------------------------------------//
|
Chris@16
|
26
|
Chris@16
|
27 // regex search result
|
Chris@16
|
28 template<typename IteratorT>
|
Chris@16
|
29 struct regex_search_result :
|
Chris@16
|
30 public iterator_range<IteratorT>
|
Chris@16
|
31 {
|
Chris@16
|
32 typedef regex_search_result<IteratorT> type;
|
Chris@16
|
33 typedef iterator_range<IteratorT> base_type;
|
Chris@16
|
34 typedef BOOST_STRING_TYPENAME base_type::value_type value_type;
|
Chris@16
|
35 typedef BOOST_STRING_TYPENAME base_type::difference_type difference_type;
|
Chris@16
|
36 typedef BOOST_STRING_TYPENAME base_type::const_iterator const_iterator;
|
Chris@16
|
37 typedef BOOST_STRING_TYPENAME base_type::iterator iterator;
|
Chris@16
|
38 typedef boost::match_results<iterator> match_results_type;
|
Chris@16
|
39
|
Chris@16
|
40 // Construction
|
Chris@16
|
41
|
Chris@16
|
42 // Construction from the match result
|
Chris@16
|
43 regex_search_result( const match_results_type& MatchResults ) :
|
Chris@16
|
44 base_type( MatchResults[0].first, MatchResults[0].second ),
|
Chris@16
|
45 m_MatchResults( MatchResults ) {}
|
Chris@16
|
46
|
Chris@16
|
47 // Construction of empty match. End iterator has to be specified
|
Chris@16
|
48 regex_search_result( IteratorT End ) :
|
Chris@16
|
49 base_type( End, End ) {}
|
Chris@16
|
50
|
Chris@16
|
51 regex_search_result( const regex_search_result& Other ) :
|
Chris@16
|
52 base_type( Other.begin(), Other.end() ),
|
Chris@16
|
53 m_MatchResults( Other.m_MatchResults ) {}
|
Chris@16
|
54
|
Chris@16
|
55 // Assignment
|
Chris@16
|
56 regex_search_result& operator=( const regex_search_result& Other )
|
Chris@16
|
57 {
|
Chris@16
|
58 base_type::operator=( Other );
|
Chris@16
|
59 m_MatchResults=Other.m_MatchResults;
|
Chris@16
|
60 return *this;
|
Chris@16
|
61 }
|
Chris@16
|
62
|
Chris@16
|
63 // Match result retrieval
|
Chris@16
|
64 const match_results_type& match_results() const
|
Chris@16
|
65 {
|
Chris@16
|
66 return m_MatchResults;
|
Chris@16
|
67 }
|
Chris@16
|
68
|
Chris@16
|
69 private:
|
Chris@16
|
70 // Saved match result
|
Chris@16
|
71 match_results_type m_MatchResults;
|
Chris@16
|
72 };
|
Chris@16
|
73
|
Chris@16
|
74 // find_regex
|
Chris@16
|
75 /*
|
Chris@16
|
76 Regex based search functor
|
Chris@16
|
77 */
|
Chris@16
|
78 template<typename RegExT>
|
Chris@16
|
79 struct find_regexF
|
Chris@16
|
80 {
|
Chris@16
|
81 typedef RegExT regex_type;
|
Chris@16
|
82 typedef const RegExT& regex_reference_type;
|
Chris@16
|
83
|
Chris@16
|
84 // Construction
|
Chris@16
|
85 find_regexF( regex_reference_type Rx, match_flag_type MatchFlags = match_default ) :
|
Chris@16
|
86 m_Rx(Rx), m_MatchFlags(MatchFlags) {}
|
Chris@16
|
87
|
Chris@16
|
88 // Operation
|
Chris@16
|
89 template< typename ForwardIteratorT >
|
Chris@16
|
90 regex_search_result<ForwardIteratorT>
|
Chris@16
|
91 operator()(
|
Chris@16
|
92 ForwardIteratorT Begin,
|
Chris@16
|
93 ForwardIteratorT End ) const
|
Chris@16
|
94 {
|
Chris@16
|
95 typedef ForwardIteratorT input_iterator_type;
|
Chris@16
|
96 typedef regex_search_result<ForwardIteratorT> result_type;
|
Chris@16
|
97
|
Chris@16
|
98 // instantiate match result
|
Chris@16
|
99 match_results<input_iterator_type> result;
|
Chris@16
|
100 // search for a match
|
Chris@16
|
101 if ( ::boost::regex_search( Begin, End, result, m_Rx, m_MatchFlags ) )
|
Chris@16
|
102 {
|
Chris@16
|
103 // construct a result
|
Chris@16
|
104 return result_type( result );
|
Chris@16
|
105 }
|
Chris@16
|
106 else
|
Chris@16
|
107 {
|
Chris@16
|
108 // empty result
|
Chris@16
|
109 return result_type( End );
|
Chris@16
|
110 }
|
Chris@16
|
111 }
|
Chris@16
|
112
|
Chris@16
|
113 private:
|
Chris@16
|
114 regex_reference_type m_Rx; // Regexp
|
Chris@16
|
115 match_flag_type m_MatchFlags; // match flags
|
Chris@16
|
116 };
|
Chris@16
|
117
|
Chris@16
|
118 } // namespace detail
|
Chris@16
|
119 } // namespace algorithm
|
Chris@16
|
120 } // namespace boost
|
Chris@16
|
121
|
Chris@16
|
122 #endif // BOOST_STRING_FIND_DETAIL_HPP
|