Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / algorithm / string / detail / finder_regex.hpp @ 2486

History | View | Annotate | Download (4.5 kB)

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