Chris@16: // Boost string_algo library find_regex.hpp header file ---------------------------// Chris@16: Chris@16: // Copyright Pavol Droba 2002-2003. Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. Chris@16: // (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: // See http://www.boost.org/ for updates, documentation, and revision history. Chris@16: Chris@16: #ifndef BOOST_STRING_FINDER_REGEX_DETAIL_HPP Chris@16: #define BOOST_STRING_FINDER_REGEX_DETAIL_HPP Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace algorithm { Chris@16: namespace detail { Chris@16: Chris@16: // regex find functor -----------------------------------------------// Chris@16: Chris@16: // regex search result Chris@16: template Chris@16: struct regex_search_result : Chris@16: public iterator_range Chris@16: { Chris@16: typedef regex_search_result type; Chris@16: typedef iterator_range base_type; Chris@16: typedef BOOST_STRING_TYPENAME base_type::value_type value_type; Chris@16: typedef BOOST_STRING_TYPENAME base_type::difference_type difference_type; Chris@16: typedef BOOST_STRING_TYPENAME base_type::const_iterator const_iterator; Chris@16: typedef BOOST_STRING_TYPENAME base_type::iterator iterator; Chris@16: typedef boost::match_results match_results_type; Chris@16: Chris@16: // Construction Chris@16: Chris@16: // Construction from the match result Chris@16: regex_search_result( const match_results_type& MatchResults ) : Chris@16: base_type( MatchResults[0].first, MatchResults[0].second ), Chris@16: m_MatchResults( MatchResults ) {} Chris@16: Chris@16: // Construction of empty match. End iterator has to be specified Chris@16: regex_search_result( IteratorT End ) : Chris@16: base_type( End, End ) {} Chris@16: Chris@16: regex_search_result( const regex_search_result& Other ) : Chris@16: base_type( Other.begin(), Other.end() ), Chris@16: m_MatchResults( Other.m_MatchResults ) {} Chris@16: Chris@16: // Assignment Chris@16: regex_search_result& operator=( const regex_search_result& Other ) Chris@16: { Chris@16: base_type::operator=( Other ); Chris@16: m_MatchResults=Other.m_MatchResults; Chris@16: return *this; Chris@16: } Chris@16: Chris@16: // Match result retrieval Chris@16: const match_results_type& match_results() const Chris@16: { Chris@16: return m_MatchResults; Chris@16: } Chris@16: Chris@16: private: Chris@16: // Saved match result Chris@16: match_results_type m_MatchResults; Chris@16: }; Chris@16: Chris@16: // find_regex Chris@16: /* Chris@16: Regex based search functor Chris@16: */ Chris@16: template Chris@16: struct find_regexF Chris@16: { Chris@16: typedef RegExT regex_type; Chris@16: typedef const RegExT& regex_reference_type; Chris@16: Chris@16: // Construction Chris@16: find_regexF( regex_reference_type Rx, match_flag_type MatchFlags = match_default ) : Chris@16: m_Rx(Rx), m_MatchFlags(MatchFlags) {} Chris@16: Chris@16: // Operation Chris@16: template< typename ForwardIteratorT > Chris@16: regex_search_result Chris@16: operator()( Chris@16: ForwardIteratorT Begin, Chris@16: ForwardIteratorT End ) const Chris@16: { Chris@16: typedef ForwardIteratorT input_iterator_type; Chris@16: typedef regex_search_result result_type; Chris@16: Chris@16: // instantiate match result Chris@16: match_results result; Chris@16: // search for a match Chris@16: if ( ::boost::regex_search( Begin, End, result, m_Rx, m_MatchFlags ) ) Chris@16: { Chris@16: // construct a result Chris@16: return result_type( result ); Chris@16: } Chris@16: else Chris@16: { Chris@16: // empty result Chris@16: return result_type( End ); Chris@16: } Chris@16: } Chris@16: Chris@16: private: Chris@16: regex_reference_type m_Rx; // Regexp Chris@16: match_flag_type m_MatchFlags; // match flags Chris@16: }; Chris@16: Chris@16: } // namespace detail Chris@16: } // namespace algorithm Chris@16: } // namespace boost Chris@16: Chris@16: #endif // BOOST_STRING_FIND_DETAIL_HPP